showKeyboard static method

void showKeyboard({
  1. required BuildContext context,
  2. required dynamic onChanged(
    1. String
    )?,
  3. dynamic onShown()?,
  4. dynamic onDismissed()?,
})

Shows the custom keyboard modal.

The keyboard is shown as a bottom sheet overlaying the current screen.

Parameters:

  • context: The build context to show the keyboard.
  • onChanged: Callback when the keyboard input changes.
  • onShown: Callback when the keyboard is shown.
  • onDismissed: Callback when the keyboard is dismissed.

Example usage:

MyKeyboard.showKeyboard(
  context: context,
  onChanged: (text) {
    print('Input: $text');
  },
  onShown: () => print('Keyboard shown'),
  onDismissed: () => print('Keyboard dismissed'),
);

Implementation

static void showKeyboard({
  required BuildContext context,
  required Function(String)? onChanged,
  Function()? onShown,
  Function()? onDismissed,
}) {
  _dismissKeyboard(context);

  showModalBottomSheet<void>(
    context: context,
    backgroundColor: Colors.transparent,
    clipBehavior: Clip.hardEdge,
    isScrollControlled: true,
    useSafeArea: true,
    barrierColor: Colors.black.withValues(alpha: 0.2),
    builder: (BuildContext context) {
      return Container(
        clipBehavior: Clip.hardEdge,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.vertical(top: Radius.circular(10)),
        ),
        padding: EdgeInsets.symmetric(vertical: 8),
        child: Keyboard(
          onChanged: onChanged,
          onShown: onShown,
          onDismissed: onDismissed,
        ),
      );
    },
  );
}