show static method

Future<String?> show(
  1. BuildContext context, {
  2. required String title,
  3. String? hintText,
  4. String? initialText,
  5. String? confirmText,
  6. String? cancelText,
  7. int? maxLength,
  8. TextInputType? keyboardType,
})

Implementation

static Future<String?> show(
  BuildContext context, {
  required String title,
  String? hintText,
  String? initialText,
  String? confirmText,
  String? cancelText,
  int? maxLength,
  TextInputType? keyboardType,
}) {
  final colors = BaseThemeProvider.colorsOf(context);
  final atomicLocale = AtomicLocalizations.of(context);
  final controller = TextEditingController(text: initialText ?? '');

  return showModalBottomSheet<String>(
    context: context,
    backgroundColor: colors.bgColorDialog,
    isScrollControlled: true,
    useSafeArea: true,
    shape: const RoundedRectangleBorder(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(16),
        topRight: Radius.circular(16),
      ),
    ),
    builder: (BuildContext context) {
      return Padding(
        padding: EdgeInsets.only(
          bottom: MediaQuery.of(context).viewInsets.bottom,
        ),
        child: Container(
          padding: const EdgeInsets.all(20),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Center(
                child: Text(
                  title,
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                    color: colors.textColorPrimary,
                  ),
                ),
              ),
              const SizedBox(height: 20),
              Container(
                decoration: BoxDecoration(
                  color: colors.bgColorInput,
                  borderRadius: BorderRadius.circular(8),
                ),
                child: TextField(
                  controller: controller,
                  keyboardType: keyboardType,
                  maxLength: maxLength,
                  decoration: InputDecoration(
                    hintText: hintText,
                    border: InputBorder.none,
                    contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                    counterText: '',
                  ),
                  autofocus: true,
                ),
              ),
              const SizedBox(height: 20),
              Row(
                children: [
                  Expanded(
                    child: TextButton(
                      onPressed: () => Navigator.of(context).pop(),
                      style: TextButton.styleFrom(
                        padding: const EdgeInsets.symmetric(vertical: 12),
                        backgroundColor: colors.buttonColorSecondaryDefault,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(8),
                        ),
                      ),
                      child: Text(
                        cancelText ?? atomicLocale.cancel,
                        style: TextStyle(
                          color: colors.textColorPrimary,
                          fontSize: 16,
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 12),
                  Expanded(
                    child: TextButton(
                      onPressed: () {
                        final text = controller.text.trim();
                        Navigator.of(context).pop(text);
                      },
                      style: TextButton.styleFrom(
                        padding: const EdgeInsets.symmetric(vertical: 12),
                        backgroundColor: colors.buttonColorPrimaryDefault,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(8),
                        ),
                      ),
                      child: Text(
                        confirmText ?? atomicLocale.confirm,
                        style: TextStyle(
                          color: colors.textColorButton,
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      );
    },
  );
}