Flutter: TextField difference between onEdittingComplete and onSubmitted

onSubmitted As the name suggestions, it’s called when user finishes editing, e.g. press “done” or “send” on the keyboard. The callback conveniently passes the value to you, so you can do your business logic with it. At the same time, since Flutter assumes the user is “done”, it will hide the on-screen keyboard. onEditingComplete This … Read more

How do I set the initial page of PageView in Flutter?

PageController constructor has named parameter initialPage. You can use it, just create the controller somewhere outside of build function: class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { PageController controller; @override void initState() { super.initState(); controller = PageController(initialPage: 3); } @override void dispose() { controller.dispose(); super.dispose(); } @override … Read more

Flutter dynamic height of ListView

You are using Flexible widget, that’s why your ListView expands. You have to change Flexible to ConstrainedBox and add shrinkWrap: true to your ListView. ConstrainedBox( constraints: BoxConstraints(maxHeight: 200, minHeight: 56.0), child: ListView.builder( shrinkWrap: true, itemBuilder: (BuildContext context, int index) { return ListTile( leading: CircleAvatar( backgroundColor: Colors.cyan, ), title: Text(‘Test restaurant’), subtitle: Text(’80m’), ); }, itemCount: … Read more

Background Image for Scaffold

Try using Stack check the following sample: @override Widget build(BuildContext context) { return Stack( children: <Widget>[ Image.asset( “resources/background.png”, height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, fit: BoxFit.cover, ), Scaffold( backgroundColor: Colors.transparent, appBar: AppBar( backgroundColor: Colors.transparent, elevation: 0.0, ), bottomNavigationBar: Container( padding: EdgeInsets.only(left: 4.0, right: 4.0), height: 44.0 + MediaQuery.of(context).padding.bottom, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ IconButton(icon: Icon(Icons.star)), IconButton(icon: … Read more

Flutter how to display datepicker when textformfield is clicked

Update 2020: As pointed by another answer @Lekr0 this can now be done using onTap() property of TextFormField. TextFormField( onTap: (){ // Below line stops keyboard from appearing FocusScope.of(context).requestFocus(new FocusNode()); // Show Date Picker Here }, ) Original Answer: Simple Way of Doing it : Wrap your TextFormField with IgnorePointer & wrap IgnorePointer with InkWell … Read more

Hide keyboard on scroll in Flutter

The ScrollView widget now has a keyboardDismissBehavior attribute that you can use for this purpose. The attribute is inherited by ListView, GridView and CustomScrollView. The attribute defaults to ScrollViewKeyboardDismissBehavior.manual but can be changed to ScrollViewKeyboardDismissBehavior.onDrag. https://api.flutter.dev/flutter/widgets/ScrollView/keyboardDismissBehavior.html Example ListView.builder( keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, itemCount: itemCount, itemBuilder: (BuildContext context, int index) { return ListTile( title: Text(‘Item ${index + 1}’), … Read more