Created
October 2, 2023 12:26
-
-
Save obumnwabude/24f57fb0ff9c632a54c2c7ffeb871437 to your computer and use it in GitHub Desktop.
Minimum Reproducible of Unfocusable Keyboard when there is GoRouter and ScreenUtil in a Flutter Project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_screenutil/flutter_screenutil.dart'; | |
import 'package:go_router/go_router.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return ScreenUtilInit( | |
designSize: const Size(392, 872), | |
ensureScreenSize: true, | |
builder: (context, _) { | |
return MaterialApp.router( | |
routerConfig: GoRouter( | |
routes: [ | |
GoRoute(path: '/', builder: (_, __) => const FormScreen()), | |
GoRoute(path: '/:path(.*)', redirect: (_, __) => '/'), | |
], | |
), | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
brightness: MediaQuery.of(context).platformBrightness, | |
useMaterial3: true, | |
), | |
); | |
}, | |
); | |
} | |
} | |
class FormScreen extends StatefulWidget { | |
const FormScreen({super.key}); | |
@override | |
State<FormScreen> createState() => _FormScreenState(); | |
} | |
class _FormScreenState extends State<FormScreen> { | |
final _formKey = GlobalKey<FormState>(); | |
final _titleCtrl = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Form/GoRouter/ScreenUtil')), | |
body: Form( | |
key: _formKey, | |
autovalidateMode: AutovalidateMode.onUserInteraction, | |
child: ListView( | |
padding: EdgeInsets.all(min(32.r, 32)), | |
children: [ | |
TextFormField( | |
controller: _titleCtrl, | |
decoration: const InputDecoration(label: Text('Title')), | |
validator: (v) => v == null || v.isEmpty ? 'Required' : null, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
heroTag: null, | |
tooltip: 'Save', | |
child: const Icon(Icons.cloud_done), | |
onPressed: () { | |
if (_formKey.currentState!.validate()) { | |
debugPrint(jsonEncode({'title': _titleCtrl.text})); | |
} | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment