How to specify ListTile height in Flutter

Applying VisualDensity allows you to expand or contract the height of list tile. VisualDensity is compactness of UI elements. Here is an example: // negative value to contract ListTile( title: Text(‘Tile title’), dense: true, visualDensity: VisualDensity(vertical: -3), // to compact onTap: () { // tap actions }, ) // positive value to expand ListTile( title: … Read more

In Flutter, how do I pass data into a Stateless Widget?

Yes you can do this simply by passing the info to the constructor. Something like this: class MyApp extends StatelessWidget { MyApp(this.yourData); final int yourData; @override Widget build(BuildContext context) { return new MaterialApp( title: ‘App Title’, theme: new ThemeData( primarySwatch: Colors.green, ), home: new MainBody(yourData), ); } } class MainBody extends StatelessWidget { MainBody(this.yourData); final … Read more

Make Function parameter optional in custom widget flutter

Optional parameters can be either positional or named, but not both. Named parameters are optional by default so you don’t have to assign the default value. If a parameter is optional but can’t be null, provide a default value. With null safety class TextInputWithIcon extends StatefulWidget { final String iconPath; final String placeHolder; final Function(bool)? … Read more

Make buttons in a row have the same width in flutter

You can use a Row wrapping your children with Expanded: Row( children: <Widget>[ Expanded( child: RaisedButton( child: Text(‘Approve’), onPressed: () => null, ), ), Expanded( child: RaisedButton( child: Text(‘Reject’), onPressed: () => null, ), ), Expanded( child: RaisedButton( child: Text(‘Need Revise’), onPressed: () => null, ), ) ], );

Looking up a deactivated widget’s ancestor is unsafe

Declare a global variable final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); then register the key on your widget build’s scaffold eg @override Widget build(BuildContext context) { return Scaffold( key: _scaffoldKey, … then on the dialog show(BuildContext context){ var dialog = Dialog( child: Container( margin: EdgeInsets.all(8.0), child: Form( child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ TextFormField( decoration: InputDecoration( labelText: … Read more