Flutter: what is Context

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
@override
Widget build(context) {
return Text('Subscribe to the AppVesto Instagram!',
style: TextStyle(color: Theme.of(context).primaryColor),
);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RaisedButton(
child: Text('Show Snack Bar'),
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.blue,
content: Text('I am SNACKBAR!!!'),
),
);
},
),
),
);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Builder(
builder: (BuildContext context) {
return RaisedButton(
child: Text('Show Snack Bar'),
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.blue,
content: Text('I am SNACKBAR!!!'),
),
);
},
);
},
),
),
);
}

We are a team of rock-star developers, which provides fully-flexible and powerful products 💥.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store