🚧 remove new keyword to get inline with dart 2 code standard.

This commit is contained in:
Nishant Srivastava
2019-07-23 03:42:56 +02:00
parent e8b433c00d
commit 6d56bfc5d4
45 changed files with 438 additions and 438 deletions

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new MyAppState();
return MyAppState();
}
}
@ -23,9 +23,9 @@ class MyAppState extends State<MyApp> {
}
List<DropdownMenuItem<String>> buildAndGetDropDownMenuItems(List fruits) {
List<DropdownMenuItem<String>> items = new List();
List<DropdownMenuItem<String>> items = List();
for (String fruit in fruits) {
items.add(new DropdownMenuItem(value: fruit, child: new Text(fruit)));
items.add(DropdownMenuItem(value: fruit, child: Text(fruit)));
}
return items;
}
@ -38,20 +38,20 @@ class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: new AppBar(
title: new Text("DropDown Button Example"),
home: Scaffold(
appBar: AppBar(
title: Text("DropDown Button Example"),
),
body: new Container(
child: new Center(
child: new Column(
body: Container(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Please choose a fruit: "),
new DropdownButton(
Text("Please choose a fruit: "),
DropdownButton(
value: _selectedFruit,
items: _dropDownMenuItems,
onChanged: changedDropDownItem,

View File

@ -1,19 +1,19 @@
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: 'Flutter Demo',
home: new Scaffold(
appBar: new AppBar(
title: new Text("Splash Screen Example"),
home: Scaffold(
appBar: AppBar(
title: Text("Splash Screen Example"),
),
body: new Center(
child: new Text("Hello World"),
body: Center(
child: Text("Hello World"),
),
),
);

View File

@ -16,22 +16,22 @@ class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Sign In")),
body: new Container(
return Scaffold(
appBar: AppBar(title: Text("Sign In")),
body: Container(
padding: const EdgeInsets.all(20.0),
child: new Center(
child: new Column(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
showLoading
? new CircularProgressIndicator()
: new RaisedButton(
? CircularProgressIndicator()
: RaisedButton(
onPressed: this.onSignin,
child: new Text("Sign In"),
child: Text("Sign In"),
color: Colors.lightBlueAccent,
),
//new RaisedButton(onPressed: this.onLogout, child: new Text("Logout"), color: Colors.amberAccent),
//RaisedButton(onPressed: this.onLogout, child: Text("Logout"), color: Colors.amberAccent),
],
),
)),

View File

@ -8,11 +8,11 @@ import 'home.dart';
import 'user.dart';
void main() {
runApp(new App());
runApp(App());
}
class App extends StatefulWidget {
AppState createState() => new AppState();
AppState createState() => AppState();
}
class AppState extends State<App> {
@ -24,7 +24,7 @@ class AppState extends State<App> {
@override
void initState() {
super.initState();
userPage = new Home(
userPage = Home(
onSignin: () {
_signin();
print("Sign");
@ -36,11 +36,11 @@ class AppState extends State<App> {
Future<FirebaseUser> _signin() async {
setState(() {
userPage = new Home(onSignin: null, onLogout: _logout, showLoading: true);
userPage = Home(onSignin: null, onLogout: _logout, showLoading: true);
});
FirebaseAuth _auth = FirebaseAuth.instance;
try {
googleSignIn = new GoogleSignIn();
googleSignIn = GoogleSignIn();
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
GoogleSignInAuthentication gauth =
await googleSignInAccount.authentication;
@ -51,7 +51,7 @@ class AppState extends State<App> {
setState(() {
_username = user.displayName;
userPage = new User(
userPage = User(
onLogout: _logout,
user: user,
);
@ -67,7 +67,7 @@ class AppState extends State<App> {
void _logout() async {
await googleSignIn.signOut();
setState(() {
userPage = new Home(
userPage = Home(
onSignin: () {
_signin();
print("Sign");
@ -82,7 +82,7 @@ class AppState extends State<App> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
home: userPage,
);
}

View File

@ -13,22 +13,22 @@ class User extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Welcome"),
return Scaffold(
appBar: AppBar(
title: Text("Welcome"),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.exit_to_app), onPressed: this.onLogout)
IconButton(
icon: Icon(Icons.exit_to_app), onPressed: this.onLogout)
],
),
body: new Container(
body: Container(
padding: const EdgeInsets.all(20.0),
child: new Center(
child: new Column(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.network(user.photoUrl),
new Text(
Image.network(user.photoUrl),
Text(
user.displayName,
textScaleFactor: 1.5,
),

View File

@ -2,23 +2,23 @@ import 'package:flutter/material.dart';
class MyGridView {
Card getStructuredGridCell(name, image) {
return new Card(
return Card(
elevation: 1.5,
child: new Column(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.down,
children: <Widget>[
new Image(image: new AssetImage('data_repo/img/' + image)),
new Center(
child: new Text(name),
Image(image: AssetImage('data_repo/img/' + image)),
Center(
child: Text(name),
)
],
));
}
GridView build() {
return new GridView.count(
return GridView.count(
primary: true,
padding: const EdgeInsets.all(1.0),
crossAxisCount: 2,

View File

@ -1,20 +1,20 @@
import 'package:flutter/material.dart';
import 'package:grid_layout/gridview.dart';
void main() => runApp(new MyApp());
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final MyGridView myGridView = new MyGridView();
final MyGridView myGridView = MyGridView();
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: new AppBar(
home: Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: new Text("GridView Example"),
title: Text("GridView Example"),
),
body: myGridView.build(),
),

View File

@ -3,12 +3,12 @@ import 'package:handling_routes/screens/about.dart';
import 'package:handling_routes/screens/home.dart';
void main() {
runApp(new MaterialApp(
home: new HomePage(), // home has implicit route set at '/'
runApp(MaterialApp(
home: HomePage(), // home has implicit route set at '/'
// Setup routes
routes: <String, WidgetBuilder>{
// Set named routes
AboutPage.routeName: (BuildContext context) => new AboutPage(),
AboutPage.routeName: (BuildContext context) => AboutPage(),
},
));
}

View File

@ -5,34 +5,34 @@ class AboutPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// AppBar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("About Page"),
title: Text("About Page"),
// App Bar background color
backgroundColor: Colors.blue,
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: new Column(
child: Center(
child: Column(
// Center content in the column
mainAxisAlignment: MainAxisAlignment.center,
// add children to the column
children: <Widget>[
// Text
new Text(
Text(
"About Page\nClick on below icon to goto Home Page",
// Setting the style for the Text
style: new TextStyle(fontSize: 20.0),
style: TextStyle(fontSize: 20.0),
// Set text alignment to center
textAlign: TextAlign.center,
),
// Icon Button
new IconButton(
icon: new Icon(
IconButton(
icon: Icon(
Icons.home,
color: Colors.red,
),

View File

@ -3,34 +3,34 @@ import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// AppBar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Home Page"),
title: Text("Home Page"),
// App Bar background color
backgroundColor: Colors.red,
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: new Column(
child: Center(
child: Column(
// Center content in the column
mainAxisAlignment: MainAxisAlignment.center,
// add children to the column
children: <Widget>[
// Text
new Text(
Text(
"Home Page\nClick on below icon to goto About Page",
// Setting the style for the Text
style: new TextStyle(fontSize: 20.0,),
style: TextStyle(fontSize: 20.0,),
// Set text alignment to center
textAlign: TextAlign.center,
),
// Icon Button
new IconButton(
icon: new Icon(
IconButton(
icon: Icon(
Icons.info,
color: Colors.blue,
),

View File

@ -1,24 +1,24 @@
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text("Image from Network"),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Image from Network"),
),
body: new Container(
child: new Column(
body: Container(
child: Column(
children: <Widget>[
// Load image from network
new Image.network(
Image.network(
'https://github.com/nisrulz/flutter-examples/raw/develop/image_from_network/img/flutter_logo.png'),
// even loads gifs
// Gif image from Giphy, all copyrights are owned by Giphy
new Image.network(
Image.network(
'https://github.com/nisrulz/flutter-examples/raw/develop/image_from_network/img/loop_anim.gif'),
],
)),

View File

@ -1,38 +1,38 @@
import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: 'Infinite List',
theme: new ThemeData(
theme: ThemeData(
primaryColor: Colors.blue, accentColor: Colors.lightBlue),
home: new RandomWords(),
home: RandomWords(),
);
}
}
class RandomWords extends StatefulWidget {
@override
createState() => new RandomWordsState();
createState() => RandomWordsState();
}
class RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _saved = new Set<WordPair>();
final _saved = Set<WordPair>();
final _biggerFont = const TextStyle(fontSize: 18.0);
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Infinite List'),
return Scaffold(
appBar: AppBar(
title: Text('Infinite List'),
centerTitle: true,
actions: <Widget>[
new IconButton(icon: new Icon(Icons.list), onPressed: _pushSaved),
IconButton(icon: Icon(Icons.list), onPressed: _pushSaved),
],
),
body: _buildSuggestions(),
@ -41,12 +41,12 @@ class RandomWordsState extends State<RandomWords> {
void _pushSaved() {
Navigator.of(context).push(
new MaterialPageRoute(
MaterialPageRoute(
builder: (context) {
final tiles = _saved.map(
(pair) {
return new ListTile(
title: new Text(
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
@ -60,11 +60,11 @@ class RandomWordsState extends State<RandomWords> {
)
.toList();
return new Scaffold(
appBar: new AppBar(
title: new Text('Saved lists'),
return Scaffold(
appBar: AppBar(
title: Text('Saved lists'),
),
body: new ListView(children: divided),
body: ListView(children: divided),
);
},
),
@ -73,12 +73,12 @@ class RandomWordsState extends State<RandomWords> {
Widget _buildRow(WordPair pair) {
final alreadySaved = _saved.contains(pair);
return new ListTile(
title: new Text(
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
trailing: new Icon(
trailing: Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
),
@ -95,7 +95,7 @@ class RandomWordsState extends State<RandomWords> {
}
Widget _buildSuggestions() {
return new ListView.builder(
return ListView.builder(
padding: const EdgeInsets.all(16.0),
// The itemBuilder callback is called once per suggested word pairing,
// and places each suggestion into a ListTile row.
@ -105,7 +105,7 @@ class RandomWordsState extends State<RandomWords> {
// to see on smaller devices.
itemBuilder: (context, i) {
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return new Divider();
if (i.isOdd) return Divider();
// The syntax "i ~/ 2" divides i by 2 and returns an integer result.
// For example: 1, 2, 3, 4, 5 becomes 0, 1, 1, 2, 2.

View File

@ -1,30 +1,30 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Load local image"),
return Scaffold(
appBar: AppBar(
title: Text("Load local image"),
),
body: new Container(
child: new Center(
child: new Text(
body: Container(
child: Center(
child: Text(
"Hello World!",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
),
),
// Set the image as the background of the Container
decoration: new BoxDecoration(
image: new DecorationImage(
decoration: BoxDecoration(
image: DecorationImage(
// Load image from assets
image: new AssetImage('data_repo/img/bg1.jpg'),
image: AssetImage('data_repo/img/bg1.jpg'),
// Make the image cover the whole area
fit: BoxFit.cover)),
));

View File

@ -3,14 +3,14 @@ import 'dart:convert';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => new MyAppState();
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
@ -18,14 +18,14 @@ class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Load local JSON file"),
return Scaffold(
appBar: AppBar(
title: Text("Load local JSON file"),
),
body: new Container(
child: new Center(
body: Container(
child: Center(
// Use future builder and DefaultAssetBundle to load the local JSON file
child: new FutureBuilder(
child: FutureBuilder(
future: DefaultAssetBundle
.of(context)
.loadString('data_repo/starwars_data.json'),
@ -33,25 +33,25 @@ class MyAppState extends State<MyApp> {
// Decode the JSON
var new_data = json.decode(snapshot.data.toString());
return new ListView.builder(
return ListView.builder(
// Build the ListView
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new Column(
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Text("Name: " + new_data[index]['name']),
new Text("Height: " + new_data[index]['height']),
new Text("Mass: " + new_data[index]['mass']),
new Text(
Text("Name: " + new_data[index]['name']),
Text("Height: " + new_data[index]['height']),
Text("Mass: " + new_data[index]['mass']),
Text(
"Hair Color: " + new_data[index]['hair_color']),
new Text(
Text(
"Skin Color: " + new_data[index]['skin_color']),
new Text(
Text(
"Eye Color: " + new_data[index]['eye_color']),
new Text(
Text(
"Birth Year: " + new_data[index]['birth_year']),
new Text("Gender: " + new_data[index]['gender'])
Text("Gender: " + new_data[index]['gender'])
],
),
);

View File

@ -4,13 +4,13 @@ import 'package:navigation_drawer/screens/home.dart';
import 'package:navigation_drawer/screens/settings.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: new HomeScreen(), // route for home is '/' implicitly
home: HomeScreen(), // route for home is '/' implicitly
routes: <String, WidgetBuilder>{
// define the routes
SettingsScreen.routeName: (BuildContext context) => new SettingsScreen(),
AccountScreen.routeName: (BuildContext context) => new AccountScreen(),
SettingsScreen.routeName: (BuildContext context) => SettingsScreen(),
AccountScreen.routeName: (BuildContext context) => AccountScreen(),
},
));
}

View File

@ -5,13 +5,13 @@ class AccountScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Account"),
return Scaffold(
appBar: AppBar(
title: Text("Account"),
),
body: new Container(
child: new Center(
child: new Text("Account Screen"),
body: Container(
child: Center(
child: Text("Account Screen"),
)),
);
}

View File

@ -4,23 +4,23 @@ import 'package:navigation_drawer/screens/settings.dart';
class HomeScreen extends StatefulWidget {
@override
HomeScreenState createState() => new HomeScreenState();
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
Drawer getNavDrawer(BuildContext context) {
var headerChild = new DrawerHeader(child: new Text("Header"));
var aboutChild = new AboutListTile(
child: new Text("About"),
var headerChild = DrawerHeader(child: Text("Header"));
var aboutChild = AboutListTile(
child: Text("About"),
applicationName: "Application Name",
applicationVersion: "v1.0.0",
applicationIcon: new Icon(Icons.adb),
icon: new Icon(Icons.info));
applicationIcon: Icon(Icons.adb),
icon: Icon(Icons.info));
ListTile getNavItem(var icon, String s, String routeName) {
return new ListTile(
leading: new Icon(icon),
title: new Text(s),
return ListTile(
leading: Icon(icon),
title: Text(s),
onTap: () {
setState(() {
// pop closes the drawer
@ -40,22 +40,22 @@ class HomeScreenState extends State<HomeScreen> {
aboutChild
];
ListView listView = new ListView(children: myNavChildren);
ListView listView = ListView(children: myNavChildren);
return new Drawer(
return Drawer(
child: listView,
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Navigation Drawer Example"),
return Scaffold(
appBar: AppBar(
title: Text("Navigation Drawer Example"),
),
body: new Container(
child: new Center(
child: new Text("Home Screen"),
body: Container(
child: Center(
child: Text("Home Screen"),
)),
// Set the nav drawer
drawer: getNavDrawer(context),

View File

@ -5,13 +5,13 @@ class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Settings"),
return Scaffold(
appBar: AppBar(
title: Text("Settings"),
),
body: new Container(
child: new Center(
child: new Text("Settings Screen"),
body: Container(
child: Center(
child: Text("Settings Screen"),
)),
);
}

View File

@ -2,17 +2,17 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Disable the debug flag
debugShowCheckedModeBanner: false,
// Home
home: new MyHome()));
home: MyHome()));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() {
return new MyHomeState();
return MyHomeState();
}
}
@ -67,31 +67,31 @@ class MyHomeState extends State<MyHome> {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text(nameOfApp),
title: Text(nameOfApp),
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: new Column(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
Text(
'$counter',
textScaleFactor: 10.0,
),
new Padding(padding: new EdgeInsets.all(10.0)),
new RaisedButton(
Padding(padding: EdgeInsets.all(10.0)),
RaisedButton(
onPressed: _onIncrementHit,
child: new Text('Increment Counter')),
new Padding(padding: new EdgeInsets.all(10.0)),
new RaisedButton(
child: Text('Increment Counter')),
Padding(padding: EdgeInsets.all(10.0)),
RaisedButton(
onPressed: _onDecrementHit,
child: new Text('Decrement Counter')),
child: Text('Decrement Counter')),
],
),
),

View File

@ -1,22 +1,22 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Simple Material App",
// Home
home: new Scaffold(
home: Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Simple Material App"),
title: Text("Simple Material App"),
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: Center(
// Add Text
child: new Text("Hello World!"),
child: Text("Hello World!"),
),
),
)));

View File

@ -1,15 +1,15 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyButton(),
runApp(MaterialApp(
home: MyButton(),
));
}
class MyButton extends StatefulWidget {
@override
MyButtonState createState() {
return new MyButtonState();
return MyButtonState();
}
}
@ -27,22 +27,22 @@ class MyButtonState extends State<MyButton> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Stateful Widget"),
return Scaffold(
appBar: AppBar(
title: Text("Stateful Widget"),
backgroundColor: Colors.green,
),
body: new Container(
child: new Center(
child: new Column(
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(displayedString, style: new TextStyle(fontSize: 40.0)),
new Padding(padding: new EdgeInsets.all(10.0)),
new RaisedButton(
child: new Text(
Text(displayedString, style: TextStyle(fontSize: 40.0)),
Padding(padding: EdgeInsets.all(10.0)),
RaisedButton(
child: Text(
"Press me",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
),
color: Colors.red,
onPressed: onPressOfButton,

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
runApp(MaterialApp(
home: MyApp(),
// Define the theme, set the primary swatch
theme: new ThemeData(primarySwatch: Colors.green),
theme: ThemeData(primarySwatch: Colors.green),
));
}
@ -15,53 +15,53 @@ class MyApp extends StatelessWidget {
final double myTextSize = 30.0;
final double myIconSize = 40.0;
final TextStyle myTextStyle =
new TextStyle(color: Colors.grey, fontSize: myTextSize);
TextStyle(color: Colors.grey, fontSize: myTextSize);
var column = new Column(
var column = Column(
// Makes the cards stretch in horizontal axis
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// Setup the card
new MyCard(
MyCard(
// Setup the text
title: new Text(
title: Text(
"Favorite",
style: myTextStyle,
),
// Setup the icon
icon:
new Icon(Icons.favorite, size: myIconSize, color: Colors.red)),
new MyCard(
title: new Text(
Icon(Icons.favorite, size: myIconSize, color: Colors.red)),
MyCard(
title: Text(
"Alarm",
style: myTextStyle,
),
icon: new Icon(Icons.alarm, size: myIconSize, color: Colors.blue)),
new MyCard(
title: new Text(
icon: Icon(Icons.alarm, size: myIconSize, color: Colors.blue)),
MyCard(
title: Text(
"Airport Shuttle",
style: myTextStyle,
),
icon: new Icon(Icons.airport_shuttle,
icon: Icon(Icons.airport_shuttle,
size: myIconSize, color: Colors.amber)),
new MyCard(
title: new Text(
MyCard(
title: Text(
"Done",
style: myTextStyle,
),
icon: new Icon(Icons.done, size: myIconSize, color: Colors.green)),
icon: Icon(Icons.done, size: myIconSize, color: Colors.green)),
],
);
return new Scaffold(
appBar: new AppBar(
title: new Text("Stateless Widget"),
return Scaffold(
appBar: AppBar(
title: Text("Stateless Widget"),
),
body: new Container(
body: Container(
// Sets the padding in the main container
padding: const EdgeInsets.only(bottom: 2.0),
child: new Center(
child: new SingleChildScrollView(child: column),
child: Center(
child: SingleChildScrollView(child: column),
),
),
);
@ -74,17 +74,17 @@ class MyCard extends StatelessWidget {
final Widget icon;
final Widget title;
// Constructor. {} here denote that they are optional values i.e you can use as: new MyCard()
// Constructor. {} here denote that they are optional values i.e you can use as: MyCard()
MyCard({this.title, this.icon});
@override
Widget build(BuildContext context) {
return new Container(
return Container(
padding: const EdgeInsets.only(bottom: 1.0),
child: new Card(
child: new Container(
child: Card(
child: Container(
padding: const EdgeInsets.all(20.0),
child: new Column(
child: Column(
children: <Widget>[this.title, this.icon],
),
),

View File

@ -12,7 +12,7 @@ import '../lib/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp());
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(title: 'Tip Calculator', home: new TipCalculator()));
runApp(MaterialApp(title: 'Tip Calculator', home: TipCalculator()));
}
class TipCalculator extends StatelessWidget {
@ -11,7 +11,7 @@ class TipCalculator extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Create first input field
TextField billAmountField = new TextField(
TextField billAmountField = TextField(
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
@ -20,12 +20,12 @@ class TipCalculator extends StatelessWidget {
billAmount = 0.0;
}
},
decoration: new InputDecoration(labelText: "Bill amount(\$)"),
decoration: InputDecoration(labelText: "Bill amount(\$)"),
);
// Create another input field
TextField tipPercentageField = new TextField(
decoration: new InputDecoration(labelText: "Tip %", hintText: "15"),
TextField tipPercentageField = TextField(
decoration: InputDecoration(labelText: "Tip %", hintText: "15"),
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
@ -36,30 +36,30 @@ class TipCalculator extends StatelessWidget {
});
// Create button
RaisedButton calculateButton = new RaisedButton(
child: new Text("Calculate"),
RaisedButton calculateButton = RaisedButton(
child: Text("Calculate"),
onPressed: () {
// Calculate tip and total
double calculatedTip = billAmount * tipPercentage / 100.0;
double total = billAmount + calculatedTip;
// Generate dialog
AlertDialog dialog = new AlertDialog(
content: new Text("Tip: \$$calculatedTip \n"
AlertDialog dialog = AlertDialog(
content: Text("Tip: \$$calculatedTip \n"
"Total: \$$total"));
// Show dialog
showDialog(context: context, builder: (BuildContext context) => dialog);
});
Container container = new Container(
Container container = Container(
padding: const EdgeInsets.all(16.0),
child: new Column(
child: Column(
children: [billAmountField, tipPercentageField, calculateButton]));
AppBar appBar = new AppBar(title: new Text("Tip Calculator"));
AppBar appBar = AppBar(title: Text("Tip Calculator"));
Scaffold scaffold = new Scaffold(appBar: appBar, body: container);
Scaffold scaffold = Scaffold(appBar: appBar, body: container);
return scaffold;
}
}

View File

@ -1,34 +1,34 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyHome(),
runApp(MaterialApp(
home: MyHome(),
));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() => new MyHomeState();
MyHomeState createState() => MyHomeState();
}
class MyHomeState extends State<MyHome> {
// Generate dialog
AlertDialog dialog = new AlertDialog(
content: new Text(
AlertDialog dialog = AlertDialog(
content: Text(
"Hello World!",
style: new TextStyle(fontSize: 30.0),
style: TextStyle(fontSize: 30.0),
));
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Using Alert Dialog"),
return Scaffold(
appBar: AppBar(
title: Text("Using Alert Dialog"),
),
body: new Container(
child: new Center(
child: new RaisedButton(
child: new Text("Hit to alert!"),
body: Container(
child: Center(
child: RaisedButton(
child: Text("Hit to alert!"),
// On press of the button
onPressed: () {
// Show dialog

View File

@ -4,16 +4,16 @@ import 'package:using_bottom_nav_bar/tabs/second.dart';
import 'package:using_bottom_nav_bar/tabs/third.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Using Tabs",
// Home
home: new MyHome()));
home: MyHome()));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() => new MyHomeState();
MyHomeState createState() => MyHomeState();
}
// SingleTickerProviderStateMixin is used for animation
@ -26,7 +26,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
super.initState();
// Initialize the Tab Controller
controller = new TabController(length: 3, vsync: this);
controller = TabController(length: 3, vsync: this);
}
@override
@ -38,37 +38,37 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Using Bottom Navigation Bar"),
title: Text("Using Bottom Navigation Bar"),
// Set the background color of the App Bar
backgroundColor: Colors.blue,
),
// Set the TabBar view as the body of the Scaffold
body: new TabBarView(
body: TabBarView(
// Add tabs as widgets
children: <Widget>[new FirstTab(), new SecondTab(), new ThirdTab()],
children: <Widget>[FirstTab(), SecondTab(), ThirdTab()],
// set the controller
controller: controller,
),
// Set the bottom navigation bar
bottomNavigationBar: new Material(
bottomNavigationBar: Material(
// set the color of the bottom navigation bar
color: Colors.blue,
// set the tab bar as the child of bottom navigation bar
child: new TabBar(
child: TabBar(
tabs: <Tab>[
new Tab(
Tab(
// set icon to the tab
icon: new Icon(Icons.favorite),
icon: Icon(Icons.favorite),
),
new Tab(
icon: new Icon(Icons.adb),
Tab(
icon: Icon(Icons.adb),
),
new Tab(
icon: new Icon(Icons.airport_shuttle),
Tab(
icon: Icon(Icons.airport_shuttle),
),
],
// setup the controller

View File

@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
class FirstTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
backgroundColor: Colors.red,
body: new Container(
child: new Center(
child: new Column(
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.favorite,
size: 160.0,
color: Colors.white,
),
new Text(
Text(
"First Tab",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
)
],
),

View File

@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
class SecondTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
backgroundColor: Colors.green,
body: new Container(
child: new Center(
child: new Column(
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.adb,
size: 160.0,
color: Colors.white,
),
new Text(
Text(
"Second Tab",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
)
],
),

View File

@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
class ThirdTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
backgroundColor: Colors.orange,
body: new Container(
child: new Center(
child: new Column(
body: Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.airport_shuttle,
size: 160.0,
color: Colors.white,
),
new Text(
Text(
"Third Tab",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
)
],
),

View File

@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
import './utils.dart' as utils;
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Using Custom Fonts",
// Home
home: new Scaffold(
home: Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Using Custom Fonts"),
title: Text("Using Custom Fonts"),
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: Center(
// Add Text
child: new Text("The quick brown fox jumps over the lazy dog",
child: Text("The quick brown fox jumps over the lazy dog",
// Center align text
textAlign: TextAlign.center,
// set a text style which defines a custom font

View File

@ -1,36 +1,36 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyEditText(),
runApp(MaterialApp(
home: MyEditText(),
));
}
class MyEditText extends StatefulWidget {
@override
MyEditTextState createState() => new MyEditTextState();
MyEditTextState createState() => MyEditTextState();
}
class MyEditTextState extends State<MyEditText> {
String results = "";
final TextEditingController controller = new TextEditingController();
final TextEditingController controller = TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Using EditText"),
return Scaffold(
appBar: AppBar(
title: Text("Using EditText"),
backgroundColor: Colors.red,
),
body: new Container(
body: Container(
padding: const EdgeInsets.all(10.0),
child: new Center(
child: new Column(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new TextField(
decoration: new InputDecoration(hintText: "Enter text here..."),
TextField(
decoration: InputDecoration(hintText: "Enter text here..."),
onSubmitted: (String str) {
setState(() {
results = results + "\n" + str;
@ -39,7 +39,7 @@ class MyEditTextState extends State<MyEditText> {
},
controller: controller,
),
new Text(results)
Text(results)
],
),
),

View File

@ -3,28 +3,28 @@ import 'package:flutter/material.dart';
import './utils.dart' as utils;
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Using Gradient",
// Home
home: new Scaffold(
home: Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Using Gradient"),
title: Text("Using Gradient"),
),
// Body
body: new Container(
body: Container(
// Center the content
child: new Center(
child: Center(
// Add Text
child: new Text(
child: Text(
"Hello World!",
style: new TextStyle(color: Colors.white),
style: TextStyle(color: Colors.white),
),
),
// Set background
decoration: new BoxDecoration(
decoration: BoxDecoration(
// Add Gradient
gradient: utils.getCustomGradient())))));
}

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
LinearGradient getCustomGradient() {
// Define a Linear Gradient
return new LinearGradient(
return LinearGradient(
colors: [Colors.pink, Colors.blueAccent],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.6, 0.0),

View File

@ -4,15 +4,15 @@ import 'package:http/http.dart' as http;
import 'dart:convert';
void main() {
runApp(new MaterialApp(
home: new MyGetHttpData(),
runApp(MaterialApp(
home: MyGetHttpData(),
));
}
// Create a stateful widget
class MyGetHttpData extends StatefulWidget {
@override
MyGetHttpDataState createState() => new MyGetHttpDataState();
MyGetHttpDataState createState() => MyGetHttpDataState();
}
// Create the state for our stateful widget
@ -44,27 +44,27 @@ class MyGetHttpDataState extends State<MyGetHttpData> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Retrieve JSON Data via HTTP GET"),
return Scaffold(
appBar: AppBar(
title: Text("Retrieve JSON Data via HTTP GET"),
),
// Create a Listview and load the data when available
body: new ListView.builder(
body: ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Center(
child: new Column(
return Container(
child: Center(
child: Column(
// Stretch the cards in horizontal axis
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Card(
child: new Container(
child: new Text(
Card(
child: Container(
child: Text(
// Read the name field value and set it in the Text widget
data[index]['name'],
// set some style to text
style: new TextStyle(
style: TextStyle(
fontSize: 20.0, color: Colors.lightBlueAccent),
),
// added padding

View File

@ -28,6 +28,6 @@ class ContactPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(body: new ContactsList(_buildContactList()));
return Scaffold(body: ContactsList(_buildContactList()));
}
}

View File

@ -9,15 +9,15 @@ class ContactsList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new ListView(
padding: new EdgeInsets.symmetric(vertical: 8.0),
return ListView(
padding: EdgeInsets.symmetric(vertical: 8.0),
children: _buildContactsList(),
);
}
List<ContactListItem> _buildContactsList() {
return _contactModal
.map((contact) => new ContactListItem(contact))
.map((contact) => ContactListItem(contact))
.toList();
}
}

View File

@ -8,9 +8,9 @@ class ContactListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new ListTile(
leading: new CircleAvatar(child: new Text(_contactModal.fullName[0])),
title: new Text(_contactModal.fullName),
subtitle: new Text(_contactModal.email));
return ListTile(
leading: CircleAvatar(child: Text(_contactModal.fullName[0])),
title: Text(_contactModal.fullName),
subtitle: Text(_contactModal.email));
}
}

View File

@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
import 'package:using_listview/contact_page.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: new AppBar(
title: new Text("Using Listview"),
home: Scaffold(
appBar: AppBar(
title: Text("Using Listview"),
),
body: new ContactPage(),
body: ContactPage(),
),
));
}

View File

@ -1,18 +1,18 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new ContactPage(), debugShowCheckedModeBanner: false,));
runApp(MaterialApp(home: ContactPage(), debugShowCheckedModeBanner: false,));
}
class ContactPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Using SnackBar"),
return Scaffold(
appBar: AppBar(
title: Text("Using SnackBar"),
),
body: new Center(
child: new MyButton(),
body: Center(
child: MyButton(),
),
);
}
@ -21,23 +21,23 @@ class ContactPage extends StatelessWidget {
class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new RaisedButton(
child: new Text('Show SnackBar'),
return RaisedButton(
child: Text('Show SnackBar'),
// On pressing the raised button
onPressed: () {
// show snackbar
Scaffold.of(context).showSnackBar(new SnackBar(
Scaffold.of(context).showSnackBar(SnackBar(
// set content of snackbar
content: new Text("Hello! I am SnackBar :)"),
content: Text("Hello! I am SnackBar :)"),
// set duration
duration: new Duration(seconds: 3),
duration: Duration(seconds: 3),
// set the action
action: new SnackBarAction(
action: SnackBarAction(
label: "Hit Me (Action)",
onPressed: () {
// When action button is pressed, show another snackbar
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text(
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"Hello! I am shown becoz you pressed Action :)"),
));
}),

View File

@ -1,51 +1,51 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Simple Material App",
// Home
home: new MyHome()));
home: MyHome()));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() => new MyHomeState();
MyHomeState createState() => MyHomeState();
}
class MyHomeState extends State<MyHome> {
// init the step to 0th position
int current_step = 0;
List<Step> my_steps = [
new Step(
Step(
// Title of the Step
title: new Text("Step 1"),
title: Text("Step 1"),
// Content, it can be any widget here. Using basic Text for this example
content: new Text("Hello!"),
content: Text("Hello!"),
isActive: true),
new Step(
title: new Text("Step 2"),
content: new Text("World!"),
Step(
title: Text("Step 2"),
content: Text("World!"),
// You can change the style of the step icon i.e number, editing, etc.
state: StepState.editing,
isActive: true),
new Step(
title: new Text("Step 3"),
content: new Text("Hello World!"),
Step(
title: Text("Step 3"),
content: Text("Hello World!"),
isActive: true),
];
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Simple Material App"),
title: Text("Simple Material App"),
),
// Body
body: new Container(
child: new Stepper(
body: Container(
child: Stepper(
// Using a variable here for handling the currentStep
currentStep: this.current_step,
// List the steps you would like to have

View File

@ -4,16 +4,16 @@ import 'package:using_tabs/tabs/second.dart';
import 'package:using_tabs/tabs/third.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
// Title
title: "Using Tabs",
// Home
home: new MyHome()));
home: MyHome()));
}
class MyHome extends StatefulWidget {
@override
MyHomeState createState() => new MyHomeState();
MyHomeState createState() => MyHomeState();
}
// SingleTickerProviderStateMixin is used for animation
@ -29,7 +29,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
super.initState();
// Initialize the Tab Controller
controller = new TabController(length: 3, vsync: this);
controller = TabController(length: 3, vsync: this);
}
@override
@ -40,17 +40,17 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
}
TabBar getTabBar() {
return new TabBar(
return TabBar(
tabs: <Tab>[
new Tab(
Tab(
// set icon to the tab
icon: new Icon(Icons.favorite),
icon: Icon(Icons.favorite),
),
new Tab(
icon: new Icon(Icons.adb),
Tab(
icon: Icon(Icons.adb),
),
new Tab(
icon: new Icon(Icons.airport_shuttle),
Tab(
icon: Icon(Icons.airport_shuttle),
),
],
// setup the controller
@ -59,7 +59,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
}
TabBarView getTabBarView(var tabs) {
return new TabBarView(
return TabBarView(
// Add tabs as widgets
children: tabs,
// set the controller
@ -72,16 +72,16 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
*/
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// Appbar
appBar: new AppBar(
appBar: AppBar(
// Title
title: new Text("Using Tabs"),
title: Text("Using Tabs"),
// Set the background color of the App Bar
backgroundColor: Colors.blue,
// Set the bottom property of the Appbar to include a Tab Bar
bottom: getTabBar()),
// Set the TabBar view as the body of the Scaffold
body: getTabBarView(<Widget>[new First(), new Second(), new Third()]));
body: getTabBarView(<Widget>[First(), Second(), Third()]));
}
}

View File

@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
class First extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new Column(
return Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.favorite,
size: 160.0,
color: Colors.red,
),
new Text("First Tab")
Text("First Tab")
],
),
),

View File

@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
class Second extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new Column(
return Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.adb,
size: 160.0,
color: Colors.green,
),
new Text("Second Tab")
Text("Second Tab")
],
),
),

View File

@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
class Third extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new Column(
return Container(
child: Center(
child: Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icon(
Icons.airport_shuttle,
size: 160.0,
color: Colors.blue,
),
new Text("Third Tab")
Text("Third Tab")
],
),
),

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyHome(),
home: MyHome(),
// Set the theme's primary color, accent color,
theme: new ThemeData(
theme: ThemeData(
primarySwatch: Colors.green,
accentColor: Colors.lightGreenAccent,
// Set background color
@ -17,20 +17,20 @@ void main() {
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
// AppBar
appBar: new AppBar(
appBar: AppBar(
// AppBar Title
title: new Text("Using Theme"),
title: Text("Using Theme"),
),
body: new Container(
body: Container(
// Another way to set the background color
decoration: new BoxDecoration(color: Colors.black87),
child: new Center(
child: new Container(
decoration: BoxDecoration(color: Colors.black87),
child: Center(
child: Container(
// use the theme accent color as background color for this widget
color: Theme.of(context).accentColor,
child: new Text(
child: Text(
'Hello World!',
// Set text style as per theme
style: Theme.of(context).textTheme.title,