Which context to use in flutter? What is the difference? - mobile

I am having trouble understanding the differences between the Widget BuildContext and the Builder BuildContext as of the following code snippets:
#override
Widget build(BuildContext context) {
and
new Builder(
builder: (BuildContext context){
By using the Widget BuildContext the SnackBar doesn't appear in the UI but an error is shown in the logs which indicates that the Scaffold.of() Context doesn't have a Scaffold while using the Builder context everything worked fine.
Scaffold.of(context).showSnackBar(
new SnackBar(content: new Text('Processing Data')));
Edit: The main.dart file:
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'APP'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final formKey = new GlobalKey<FormState>();
String username;
#override
//This context
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Flexible(
child: new Container(
child: new Center(
child: new Text(widget.title),
),
),
flex: 1,
),
new Form(
key: formKey,
child:
new Row(children: <Widget>[
new Flexible(child:
new Container(
margin: EdgeInsets.zero,
child: new TextFormField(
decoration:
new InputDecoration(
hintText: 'Username',
labelText: "1",
labelStyle: new TextStyle(color: new Color.fromARGB(255, 0, 0, 0)),
),
validator: (val) => val.isEmpty? 'Username can\'t be empty.' : null,
),
),
flex: 1,
),
new Flexible(child:
new Container(
margin: EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: new TextFormField(
decoration: new InputDecoration(
border: InputBorder.none,
hintText: "Password",
),
validator: (val) => val.isEmpty? 'Password can\'t be empty.' : null,
obscureText: true,
),
),
flex: 1,
),
new Container(
child:
new Builder(
//And this context
builder: (BuildContext context){
return RaisedButton(
child: new Text("Sign in"),
onPressed: (){
if (formKey.currentState.validate()) {
// If the form is valid, display a snackbar. In the real world, you'd
// often want to call a server or save the information in a database
Scaffold.of(context).showSnackBar(
new SnackBar(content: new Text('Processing Data')));
}
},
);
},
),
),
],
),
),
],
),
),
);
}
}

It is better if you reference the current Scaffold where you want the SnackBar to appear in by using they key property.
final GloabalKey<ScaffoldState> _key = GlobalKey<ScaffoldState>();
Scaffold(
key:_key,
...
)
show the snack bar
_key.currentState.showSnackBar(mySnackBar)
Note that each builder method gets a context to be able to reference it when using widgets that needs access to this context. In your code, the context is being confused, if you change your build method context to be something unique like (Buildcontext scaffoldContext) and then use Scaffold.of(scaffoldContext) I am not sure if this will work as I see this confusion by in Flutter quite often.
Anyway the solution above is way cleaner.

Related

Want to refer to a particular container in a list view which is made scrollable horizontally

I have a column which has two widgets wherein there's a list view of 3 different containers which is scrollable horizontally and there an inkwell.
What Inkwell is doing is that it is having a click functionality wherein if I click on that inkwell it should redirect me to one of the containers in the list view and also it should be able to scroll in the horizontal axis.
But what I have coded down is it is navigating me to the desired screen but the thing is that the app bar is getting vanished and the scrolling ability is also not there and also few yellow line errors were also coming.
Code Snippet:
import 'package:book/shared/colors.dart';
import 'package:flutter/material.dart';
class ListExample extends StatefulWidget {
#override
_ListExampleState createState() => _ListExampleState();
}
class _ListExampleState extends State<ListExample> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
),
body: Column(
children: [
Expanded(
child: ListView(
scrollDirection: Axis.horizontal,
children: [
Container(
height: 800,
width: 1200,
child: Center(
child: Text('Screen 1'), // 1st Page.
),
),
Screen2(), // 2nd Page
Container(
height: 800,
width: 1200,
child: Center(
child: Text('Screen 3'), // 3rd Page.
),
),
],
),
),
Expanded(
child: Row(
children: [
Container(
height: 60,
width: 800,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
),
color: AppColors.getLightBlue(),
),
),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Screen2(), /// Using the navigator is not solving the problem
),
);
},
child: Text(
'Screen 2'), // The name should change as we navigate throgh differnt screen
),
],
),
)
],
),
);
}
}
class Screen2 extends StatelessWidget {
const Screen2({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
height: 800,
width: 1200,
child: Center(
child: Text('Screen 2'), // 2nd Page.
),
);
}
}
Please help me solve the error.
Tried the few packages such as scrollable_position_list, etc but nothing helped me with this.

Is there a way to divide data coming from an API in flutter?

If I'm getting big amounts of data coming from an API and I want to divide them into parts based on the meaning of the words, what's the proper way to do it in flutter?
You can use the pagination package. With this, you can divide your data into pages and you can fetch the only related page data with offset. You can look at the sample code:
import 'package:example/user.dart';
import 'package:faker/faker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:pagination/pagination.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'PaginationView Demo',
theme: ThemeData(
primarySwatch: Colors.cyan,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'PaginationView Example',
style: TextStyle(
color: Colors.white,
),
),
),
body: PaginationList<User>(
shrinkWrap: true,
padding: EdgeInsets.only(
left: 5,
right: 5,
),
separatorWidget: Container(
height: 0.5,
color: Colors.black,
),
itemBuilder: (BuildContext context, User user) {
return ListTile(
title:
Text(user.prefix + " " + user.firstName + " " + user.lastName),
subtitle: Text(user.designation),
leading: IconButton(
icon: Icon(Icons.person_outline),
onPressed: () => null,
),
onTap: () => print(user.designation),
trailing: Icon(
Icons.call,
color: Colors.green,
),
);
},
pageFetch: pageFetch,
onError: (dynamic error) => Center(
child: Text('Something Went Wrong'),
),
initialData: <User>[
User(
faker.person.prefix(),
faker.person.firstName(),
faker.person.lastName(),
faker.company.position(),
),
User(
faker.person.prefix(),
faker.person.firstName(),
faker.person.lastName(),
faker.company.position(),
),
],
onEmpty: Center(
child: Text('Empty List'),
),
),
);
}
Future<List<User>> pageFetch(int offset) async {
final Faker faker = Faker();
final List<User> upcomingList = List.generate(
15,
(int index) => User(
faker.person.prefix(),
faker.person.firstName(),
faker.person.lastName(),
faker.company.position(),
),
);
await Future<List<User>>.delayed(
Duration(milliseconds: 1500),
);
return upcomingList;
}
}

Flutter - Sliver Layout horizontal scroll inside Sliver List

I try to make horizontal scrollable list inside Sliver List (CustomScrollview - SliverList)
This is my Code:
import 'package:flutter/material.dart';
class DetailScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
DetailAppBar(),
SliverPadding(
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildListDelegate(
[
Card(child: Text('data'),),
Card(child: Text('data'),),
Card(child: Text('data'),),
Card(child: Text('data'),),
// Scrollable horizontal widget here
],
),
),
),
],
),
bottomNavigationBar: NavigationButton());
}
}
Can you give me example or solution to this case? i really need some help.
Use a ListView inside of a SliverToBoxAdapter.
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverPadding(
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildListDelegate(
[
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
],
),
),
),
SliverToBoxAdapter(
child: Container(
height: 100.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) {
return Container(
width: 100.0,
child: Card(
child: Text('data'),
),
);
},
),
),
),
],
),
);
}
the other solution doesn't work for me as it gives error when I use a ListView
here is a class I wrote called HorizontalSliverList which does the job nice and easy
here is the class you need to copy:
class HorizontalSliverList extends StatelessWidget {
final List<Widget> children;
final EdgeInsets listPadding;
final Widget divider;
const HorizontalSliverList({
Key key,
#required this.children,
this.listPadding = const EdgeInsets.all(8),
this.divider,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Padding(
padding: listPadding,
child: Row(children: [
for (var i = 0; i < children.length; i++) ...[
children[i],
if (i != children.length - 1) addDivider(),
],
]),
),
),
);
}
Widget addDivider() => divider ?? Padding(padding: const EdgeInsets.symmetric(horizontal: 8));
}

update checkbox and return value from dialog in flutter

I am trying to add some city list to a dialog with checkbox so that i need to implement multiple click on items. what I am trying to do is given below.
onPressed from button calls Rest Service and on success result I just show a dialog
void showCityDialog(BuildContext context) {
SimpleDialog dialog = new SimpleDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Text(
"CITIES",
style: TextStyle(fontSize: 18.0, color: Colors.black),
textAlign: TextAlign.center,
),
new RaisedButton(
onPressed: () {print("clicked");},
color: Color(0xFFfab82b),
child: new Text(
"Done",
style: TextStyle(color: Colors.white),
),)],),
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
constraints: BoxConstraints(maxHeight: 500.0),
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: cityData.length,
itemBuilder: (context, position) {
return new CheckboxListTile(
value: checkboxValueCity,
onChanged: (bool value) {
setState(() {
checkboxValueCity = value;
});
},
activeColor: Color(0xFFfab82b),
dense: true,
title: Text(
cityData[position].city_name,
style: TextStyle(fontSize: 16.0, color: Colors.black),
),);},),),],)],);
showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
});
}
checkboxValueCity is a boolean variable in class , on click of chekboxListItem i need to update checkbox value as checked and uncheced. At the same time need to add/remove that item to a list which is also inside that class.
But in my code checkbox is not refershing on every click but when i close that box and open it again checkbox is checked. then how can i get multiple click from tile and how can i return list from dialog?
Your dialog needs to be a StatefulWidget (Flutter Github issue). The member variable that tracks selection state needs to be in the dialog class. You can use a callback to update a member variable in your parent class with the List of selected cities. There also seem to be some issues using a ListView.builder inside of a SimpleDialog or AlertDialog (search the Flutter Github for issues) so I used a plain Dialog.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Checkbox Dialog Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Checkbox Dialog Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool checkboxValueCity = false;
List<String> allCities = ['Alpha', 'Beta', 'Gamma'];
List<String> selectedCities = [];
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return _MyDialog(
cities: allCities,
selectedCities: selectedCities,
onSelectedCitiesListChanged: (cities) {
selectedCities = cities;
print(selectedCities);
});
});
}),
);
}
}
class _MyDialog extends StatefulWidget {
_MyDialog({
this.cities,
this.selectedCities,
this.onSelectedCitiesListChanged,
});
final List<String> cities;
final List<String> selectedCities;
final ValueChanged<List<String>> onSelectedCitiesListChanged;
#override
_MyDialogState createState() => _MyDialogState();
}
class _MyDialogState extends State<_MyDialog> {
List<String> _tempSelectedCities = [];
#override
void initState() {
_tempSelectedCities = widget.selectedCities;
super.initState();
}
#override
Widget build(BuildContext context) {
return Dialog(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'CITIES',
style: TextStyle(fontSize: 18.0, color: Colors.black),
textAlign: TextAlign.center,
),
RaisedButton(
onPressed: () {
Navigator.pop(context);
},
color: Color(0xFFfab82b),
child: Text(
'Done',
style: TextStyle(color: Colors.white),
),
),
],
),
Expanded(
child: ListView.builder(
itemCount: widget.cities.length,
itemBuilder: (BuildContext context, int index) {
final cityName = widget.cities[index];
return Container(
child: CheckboxListTile(
title: Text(cityName),
value: _tempSelectedCities.contains(cityName),
onChanged: (bool value) {
if (value) {
if (!_tempSelectedCities.contains(cityName)) {
setState(() {
_tempSelectedCities.add(cityName);
});
}
} else {
if (_tempSelectedCities.contains(cityName)) {
setState(() {
_tempSelectedCities.removeWhere(
(String city) => city == cityName);
});
}
}
widget
.onSelectedCitiesListChanged(_tempSelectedCities);
}),
);
}),
),
],
),
);
}
}
Use StatefulBuilder to update Widgets only inside Dialog. StatefulBuilder is best for update sebsection of the widget tree where
state is needed.
simple code snippet
void _showDialog() {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder( // StatefulBuilder
builder: (context, setState) {
return AlertDialog(
actions: <Widget>[
Container(
width: 400,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"Student Attendence",
style: TextStyle(fontSize: 20),
),
SizedBox(
height: 5,
),
Container(
height: 2,
color: Colors.black,
),
SizedBox(
height: 15,
),
CheckboxListTile(
value: user1,
title: Text("user1"),
onChanged: (value){
setState(() {
user1=value;
});
},
),
Divider(
height: 10,
),
CheckboxListTile(
value: user2,
title: Text("user2"),
onChanged: (value){
setState(() {
user2=value;
});
},
),
Divider(
height: 10,
),
CheckboxListTile(
value: user3,
title: Text("user3"),
onChanged: (value){
setState(() {
user3=value;
});
},
),
Divider(
height: 10,
),
CheckboxListTile(
value: user4,
title: Text("user4"),
onChanged: (value){
setState(() {
user4=value;
});
},
),
Divider(
height: 10,
),
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Material(
elevation: 5.0,
color: Colors.blue[900],
child: MaterialButton(
padding: EdgeInsets.fromLTRB(
10.0, 5.0, 10.0, 5.0),
onPressed: () {},
child: Text("Save",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 15,
)),
),
),
Material(
elevation: 5.0,
color: Colors.blue[900],
child: MaterialButton(
padding: EdgeInsets.fromLTRB(
10.0, 5.0, 10.0, 5.0),
onPressed: () {
setState(() {
Navigator.of(context).pop();
});
},
child: Text("Cancel",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 15,
)),
),
),
Material(
elevation: 5.0,
color: Colors.blue[900],
child: MaterialButton(
padding: EdgeInsets.fromLTRB(
10.0, 5.0, 10.0, 5.0),
onPressed: () {},
child: Text("Select All",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 15,
)),
),
),
],
)
],
))
],
);
},
);
},
);
}
example
Although Albert's answer works, you need not go thru all that. Simply wrap the content: with a StatefulBuilder, voila!
https://api.flutter.dev/flutter/widgets/StatefulBuilder-class.html.
Note: It is important where you declare the variable(s) you want to change.
I modified your code a bit, I want when users check the list, the list won't be updated to the main view, but they will when users click the "Update" button.
But some how, it doesn't work. Can you please check ?
Thank you very much
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Checkbox Dialog Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Checkbox Dialog Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool checkboxValueCity = false;
List<String> allCities = ['Alpha', 'Beta', 'Gamma'];
List<String> selectedCities = [];
List<String> selectedCitiesTemp = [];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("App Bar"),
),
body: Center(
child: Column(
children: <Widget>[
_list(),
RaisedButton(
child: Text("Update From TMP List"),
onPressed: () {
setState(() {
selectedCities = selectedCitiesTemp;
});
},
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return _MyDialog(
cities: allCities,
selectedCities: selectedCities,
onSelectedCitiesListChanged: (cities) {
setState(() {
selectedCitiesTemp = cities;
});
},
);
});
}),
);
}
Widget _list() {
List<Widget> list = [];
for(String item in selectedCities) {
list.add(ListTile(
title: Text(item),
));
}
return Column(
children: list
);
}
}
class _MyDialog extends StatefulWidget {
_MyDialog({
this.cities,
this.selectedCities,
this.onSelectedCitiesListChanged,
});
final List<String> cities;
final List<String> selectedCities;
final ValueChanged<List<String>> onSelectedCitiesListChanged;
#override
_MyDialogState createState() => _MyDialogState();
}
class _MyDialogState extends State<_MyDialog> {
List<String> _tempSelectedCities = [];
#override
void initState() {
_tempSelectedCities = widget.selectedCities;
super.initState();
}
#override
Widget build(BuildContext context) {
return Dialog(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'CITIES',
style: TextStyle(fontSize: 18.0, color: Colors.black),
textAlign: TextAlign.center,
),
],
),
Expanded(
child: ListView.builder(
itemCount: widget.cities.length,
itemBuilder: (BuildContext context, int index) {
final cityName = widget.cities[index];
return Container(
child: CheckboxListTile(
title: Text(cityName),
value: _tempSelectedCities.contains(cityName),
onChanged: (bool value) {
if (value) {
if (!_tempSelectedCities.contains(cityName)) {
setState(() {
_tempSelectedCities.add(cityName);
});
}
} else {
if (_tempSelectedCities.contains(cityName)) {
setState(() {
_tempSelectedCities.removeWhere(
(String city) => city == cityName);
});
}
}
widget.onSelectedCitiesListChanged(_tempSelectedCities);
}),
);
}),
),
],
),
);
}
}

Flutter checkbox unwanted touch space

I tried to create a login screen using flutter, there I added remember me checkbox, but I could not align it correctly,
Flutter checkbox took unwanted space around itself, for the provide good touch user experience.
This is the how my layout show,
Check below code,
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Row(
children: <Widget>[
new Checkbox(
activeColor: Colors.grey,
value: _isChecked,
onChanged: (bool value) {
_onChecked(value);
},
),
new GestureDetector(
onTap: () => print("Remember me"),
child: new Text(
"Remember me",
style: new TextStyle(color: Colors.white70),
),
)
],
),
new Text(
"Forgot password ?",
style: new TextStyle(color: Colors.white70),
)
],
),
Use SizedBox
The widget is basically made for resizing its child.
SizedBox(
width: 15,
height: 15,
child: Checkbox(value: false, onChanged: null)
)
EDIT
Short Answer
Checkbox(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
...
)
..................
Long Answer
You can achieve this by customising the Checkbox widget.
Create a CustomCheckbox using the exact code from
flutter/packages/flutter/lib/src/material/checkbox.dart.
Add a new field to your CustomCheckbox widget
final bool useTapTarget;
Make sure to add the new field to your constructor with it default
value set to true.
this.useTapTarget = true
Modify the build method in the _CheckboxState method. Add this
block of code above the return call.
Size noTapTargetSize = Size(CustomCheckbox.width,
CustomCheckbox.width);
final BoxConstraints additionalConstraints =
BoxConstraints.tight(widget
.useTapTarget? size : noTapTargetSize);
Finally, use your CustomCheckbox widget in your code, and set your
custom field to false to remove material padding. example
Container(
margin: EdgeInsets.only(right: 15),
child:CustomCheckbox(
value: _checked,
materialTapTargetSize: null,
onChanged: _onCheckBoxChange,
useTapTarget: false,
activeColor: Colors.teal),
)
Try this then,
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'NonStopIO',
theme: new ThemeData(
primarySwatch: Colors.red,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _rememberMeFlag = false;
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('NonStopIO'),
),
body: new Container(
color: Colors.black38,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
margin: new EdgeInsets.symmetric(vertical: 5.0, horizontal: 35.0),
color: Colors.white70,
height: 50.0,
),
new Container(
margin: new EdgeInsets.symmetric(vertical: 5.0, horizontal: 35.0),
color: Colors.white70,
height: 50.0,
),
new Container(
margin: new EdgeInsets.symmetric(vertical: 5.0, horizontal: 20.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Row(
children: <Widget>[
new GestureDetector(
child: new Row(
children: <Widget>[
new Checkbox(
value: _rememberMeFlag,
onChanged: (value) => setState(() {
_rememberMeFlag = !_rememberMeFlag;
}),
),
new Text(
"Remember me",
style: new TextStyle(color: Colors.white70),
)
],
),
onTap: () => setState(() {
_rememberMeFlag = !_rememberMeFlag;
}),
),
],
),
new Container(
margin: new EdgeInsets.only(right: 15.0),
child: new Text(
"Forgot password ?",
style: new TextStyle(color: Colors.white70),
),
)
],
)),
new Container(
margin: new EdgeInsets.symmetric(vertical: 5.0, horizontal: 35.0),
color: Colors.orange,
height: 50.0,
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Here, I have adjusted the margin to align the Checkbox and Forgot password Text.

Resources