mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-08 20:50:04 +00:00
🚧 remove new keyword to get inline with dart 2 code standard.
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(new MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
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>> buildAndGetDropDownMenuItems(List fruits) {
|
||||||
List<DropdownMenuItem<String>> items = new List();
|
List<DropdownMenuItem<String>> items = List();
|
||||||
for (String fruit in fruits) {
|
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;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -38,20 +38,20 @@ class MyAppState extends State<MyApp> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("DropDown Button Example"),
|
title: Text("DropDown Button Example"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text("Please choose a fruit: "),
|
Text("Please choose a fruit: "),
|
||||||
new DropdownButton(
|
DropdownButton(
|
||||||
value: _selectedFruit,
|
value: _selectedFruit,
|
||||||
items: _dropDownMenuItems,
|
items: _dropDownMenuItems,
|
||||||
onChanged: changedDropDownItem,
|
onChanged: changedDropDownItem,
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(new MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Splash Screen Example"),
|
title: Text("Splash Screen Example"),
|
||||||
),
|
),
|
||||||
body: new Center(
|
body: Center(
|
||||||
child: new Text("Hello World"),
|
child: Text("Hello World"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,22 +16,22 @@ class Home extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(title: new Text("Sign In")),
|
appBar: AppBar(title: Text("Sign In")),
|
||||||
body: new Container(
|
body: Container(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
showLoading
|
showLoading
|
||||||
? new CircularProgressIndicator()
|
? CircularProgressIndicator()
|
||||||
: new RaisedButton(
|
: RaisedButton(
|
||||||
onPressed: this.onSignin,
|
onPressed: this.onSignin,
|
||||||
child: new Text("Sign In"),
|
child: Text("Sign In"),
|
||||||
color: Colors.lightBlueAccent,
|
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),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import 'home.dart';
|
|||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new App());
|
runApp(App());
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends StatefulWidget {
|
class App extends StatefulWidget {
|
||||||
AppState createState() => new AppState();
|
AppState createState() => AppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppState extends State<App> {
|
class AppState extends State<App> {
|
||||||
@@ -24,7 +24,7 @@ class AppState extends State<App> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
userPage = new Home(
|
userPage = Home(
|
||||||
onSignin: () {
|
onSignin: () {
|
||||||
_signin();
|
_signin();
|
||||||
print("Sign");
|
print("Sign");
|
||||||
@@ -36,11 +36,11 @@ class AppState extends State<App> {
|
|||||||
|
|
||||||
Future<FirebaseUser> _signin() async {
|
Future<FirebaseUser> _signin() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
userPage = new Home(onSignin: null, onLogout: _logout, showLoading: true);
|
userPage = Home(onSignin: null, onLogout: _logout, showLoading: true);
|
||||||
});
|
});
|
||||||
FirebaseAuth _auth = FirebaseAuth.instance;
|
FirebaseAuth _auth = FirebaseAuth.instance;
|
||||||
try {
|
try {
|
||||||
googleSignIn = new GoogleSignIn();
|
googleSignIn = GoogleSignIn();
|
||||||
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
|
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
|
||||||
GoogleSignInAuthentication gauth =
|
GoogleSignInAuthentication gauth =
|
||||||
await googleSignInAccount.authentication;
|
await googleSignInAccount.authentication;
|
||||||
@@ -51,7 +51,7 @@ class AppState extends State<App> {
|
|||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_username = user.displayName;
|
_username = user.displayName;
|
||||||
userPage = new User(
|
userPage = User(
|
||||||
onLogout: _logout,
|
onLogout: _logout,
|
||||||
user: user,
|
user: user,
|
||||||
);
|
);
|
||||||
@@ -67,7 +67,7 @@ class AppState extends State<App> {
|
|||||||
void _logout() async {
|
void _logout() async {
|
||||||
await googleSignIn.signOut();
|
await googleSignIn.signOut();
|
||||||
setState(() {
|
setState(() {
|
||||||
userPage = new Home(
|
userPage = Home(
|
||||||
onSignin: () {
|
onSignin: () {
|
||||||
_signin();
|
_signin();
|
||||||
print("Sign");
|
print("Sign");
|
||||||
@@ -82,7 +82,7 @@ class AppState extends State<App> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
home: userPage,
|
home: userPage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,22 +13,22 @@ class User extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Welcome"),
|
title: Text("Welcome"),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
new IconButton(
|
IconButton(
|
||||||
icon: new Icon(Icons.exit_to_app), onPressed: this.onLogout)
|
icon: Icon(Icons.exit_to_app), onPressed: this.onLogout)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Image.network(user.photoUrl),
|
Image.network(user.photoUrl),
|
||||||
new Text(
|
Text(
|
||||||
user.displayName,
|
user.displayName,
|
||||||
textScaleFactor: 1.5,
|
textScaleFactor: 1.5,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,23 +2,23 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class MyGridView {
|
class MyGridView {
|
||||||
Card getStructuredGridCell(name, image) {
|
Card getStructuredGridCell(name, image) {
|
||||||
return new Card(
|
return Card(
|
||||||
elevation: 1.5,
|
elevation: 1.5,
|
||||||
child: new Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
verticalDirection: VerticalDirection.down,
|
verticalDirection: VerticalDirection.down,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Image(image: new AssetImage('data_repo/img/' + image)),
|
Image(image: AssetImage('data_repo/img/' + image)),
|
||||||
new Center(
|
Center(
|
||||||
child: new Text(name),
|
child: Text(name),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
GridView build() {
|
GridView build() {
|
||||||
return new GridView.count(
|
return GridView.count(
|
||||||
primary: true,
|
primary: true,
|
||||||
padding: const EdgeInsets.all(1.0),
|
padding: const EdgeInsets.all(1.0),
|
||||||
crossAxisCount: 2,
|
crossAxisCount: 2,
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:grid_layout/gridview.dart';
|
import 'package:grid_layout/gridview.dart';
|
||||||
|
|
||||||
void main() => runApp(new MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
final MyGridView myGridView = new MyGridView();
|
final MyGridView myGridView = MyGridView();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
// 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.
|
// the App.build method, and use it to set our appbar title.
|
||||||
title: new Text("GridView Example"),
|
title: Text("GridView Example"),
|
||||||
),
|
),
|
||||||
body: myGridView.build(),
|
body: myGridView.build(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import 'package:handling_routes/screens/about.dart';
|
|||||||
import 'package:handling_routes/screens/home.dart';
|
import 'package:handling_routes/screens/home.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new HomePage(), // home has implicit route set at '/'
|
home: HomePage(), // home has implicit route set at '/'
|
||||||
// Setup routes
|
// Setup routes
|
||||||
routes: <String, WidgetBuilder>{
|
routes: <String, WidgetBuilder>{
|
||||||
// Set named routes
|
// Set named routes
|
||||||
AboutPage.routeName: (BuildContext context) => new AboutPage(),
|
AboutPage.routeName: (BuildContext context) => AboutPage(),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,34 +5,34 @@ class AboutPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// AppBar
|
// AppBar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("About Page"),
|
title: Text("About Page"),
|
||||||
// App Bar background color
|
// App Bar background color
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// Center content in the column
|
// Center content in the column
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
// add children to the column
|
// add children to the column
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Text
|
// Text
|
||||||
new Text(
|
Text(
|
||||||
"About Page\nClick on below icon to goto Home Page",
|
"About Page\nClick on below icon to goto Home Page",
|
||||||
// Setting the style for the Text
|
// Setting the style for the Text
|
||||||
style: new TextStyle(fontSize: 20.0),
|
style: TextStyle(fontSize: 20.0),
|
||||||
// Set text alignment to center
|
// Set text alignment to center
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
// Icon Button
|
// Icon Button
|
||||||
new IconButton(
|
IconButton(
|
||||||
icon: new Icon(
|
icon: Icon(
|
||||||
Icons.home,
|
Icons.home,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,34 +3,34 @@ import 'package:flutter/material.dart';
|
|||||||
class HomePage extends StatelessWidget {
|
class HomePage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// AppBar
|
// AppBar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Home Page"),
|
title: Text("Home Page"),
|
||||||
// App Bar background color
|
// App Bar background color
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// Center content in the column
|
// Center content in the column
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
// add children to the column
|
// add children to the column
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Text
|
// Text
|
||||||
new Text(
|
Text(
|
||||||
"Home Page\nClick on below icon to goto About Page",
|
"Home Page\nClick on below icon to goto About Page",
|
||||||
// Setting the style for the Text
|
// Setting the style for the Text
|
||||||
style: new TextStyle(fontSize: 20.0,),
|
style: TextStyle(fontSize: 20.0,),
|
||||||
// Set text alignment to center
|
// Set text alignment to center
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
// Icon Button
|
// Icon Button
|
||||||
new IconButton(
|
IconButton(
|
||||||
icon: new Icon(
|
icon: Icon(
|
||||||
Icons.info,
|
Icons.info,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(new MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Image from Network"),
|
title: Text("Image from Network"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Load image from network
|
// Load image from network
|
||||||
new Image.network(
|
Image.network(
|
||||||
'https://github.com/nisrulz/flutter-examples/raw/develop/image_from_network/img/flutter_logo.png'),
|
'https://github.com/nisrulz/flutter-examples/raw/develop/image_from_network/img/flutter_logo.png'),
|
||||||
// even loads gifs
|
// even loads gifs
|
||||||
// Gif image from Giphy, all copyrights are owned by Giphy
|
// 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'),
|
'https://github.com/nisrulz/flutter-examples/raw/develop/image_from_network/img/loop_anim.gif'),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
import 'package:english_words/english_words.dart';
|
import 'package:english_words/english_words.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() => runApp(new MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Infinite List',
|
title: 'Infinite List',
|
||||||
theme: new ThemeData(
|
theme: ThemeData(
|
||||||
primaryColor: Colors.blue, accentColor: Colors.lightBlue),
|
primaryColor: Colors.blue, accentColor: Colors.lightBlue),
|
||||||
home: new RandomWords(),
|
home: RandomWords(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RandomWords extends StatefulWidget {
|
class RandomWords extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
createState() => new RandomWordsState();
|
createState() => RandomWordsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class RandomWordsState extends State<RandomWords> {
|
class RandomWordsState extends State<RandomWords> {
|
||||||
final _suggestions = <WordPair>[];
|
final _suggestions = <WordPair>[];
|
||||||
final _saved = new Set<WordPair>();
|
final _saved = Set<WordPair>();
|
||||||
final _biggerFont = const TextStyle(fontSize: 18.0);
|
final _biggerFont = const TextStyle(fontSize: 18.0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text('Infinite List'),
|
title: Text('Infinite List'),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
new IconButton(icon: new Icon(Icons.list), onPressed: _pushSaved),
|
IconButton(icon: Icon(Icons.list), onPressed: _pushSaved),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: _buildSuggestions(),
|
body: _buildSuggestions(),
|
||||||
@@ -41,12 +41,12 @@ class RandomWordsState extends State<RandomWords> {
|
|||||||
|
|
||||||
void _pushSaved() {
|
void _pushSaved() {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
new MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
final tiles = _saved.map(
|
final tiles = _saved.map(
|
||||||
(pair) {
|
(pair) {
|
||||||
return new ListTile(
|
return ListTile(
|
||||||
title: new Text(
|
title: Text(
|
||||||
pair.asPascalCase,
|
pair.asPascalCase,
|
||||||
style: _biggerFont,
|
style: _biggerFont,
|
||||||
),
|
),
|
||||||
@@ -60,11 +60,11 @@ class RandomWordsState extends State<RandomWords> {
|
|||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text('Saved lists'),
|
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) {
|
Widget _buildRow(WordPair pair) {
|
||||||
final alreadySaved = _saved.contains(pair);
|
final alreadySaved = _saved.contains(pair);
|
||||||
return new ListTile(
|
return ListTile(
|
||||||
title: new Text(
|
title: Text(
|
||||||
pair.asPascalCase,
|
pair.asPascalCase,
|
||||||
style: _biggerFont,
|
style: _biggerFont,
|
||||||
),
|
),
|
||||||
trailing: new Icon(
|
trailing: Icon(
|
||||||
alreadySaved ? Icons.favorite : Icons.favorite_border,
|
alreadySaved ? Icons.favorite : Icons.favorite_border,
|
||||||
color: alreadySaved ? Colors.red : null,
|
color: alreadySaved ? Colors.red : null,
|
||||||
),
|
),
|
||||||
@@ -95,7 +95,7 @@ class RandomWordsState extends State<RandomWords> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSuggestions() {
|
Widget _buildSuggestions() {
|
||||||
return new ListView.builder(
|
return ListView.builder(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
// The itemBuilder callback is called once per suggested word pairing,
|
// The itemBuilder callback is called once per suggested word pairing,
|
||||||
// and places each suggestion into a ListTile row.
|
// and places each suggestion into a ListTile row.
|
||||||
@@ -105,7 +105,7 @@ class RandomWordsState extends State<RandomWords> {
|
|||||||
// to see on smaller devices.
|
// to see on smaller devices.
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
// Add a one-pixel-high divider widget before each row in theListView.
|
// 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.
|
// 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.
|
// For example: 1, 2, 3, 4, 5 becomes 0, 1, 1, 2, 2.
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyApp(),
|
home: MyApp(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Load local image"),
|
title: Text("Load local image"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Text(
|
child: Text(
|
||||||
"Hello World!",
|
"Hello World!",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Set the image as the background of the Container
|
// Set the image as the background of the Container
|
||||||
decoration: new BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
image: new DecorationImage(
|
image: DecorationImage(
|
||||||
// Load image from assets
|
// 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
|
// Make the image cover the whole area
|
||||||
fit: BoxFit.cover)),
|
fit: BoxFit.cover)),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyApp(),
|
home: MyApp(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyAppState createState() => new MyAppState();
|
MyAppState createState() => MyAppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyAppState extends State<MyApp> {
|
class MyAppState extends State<MyApp> {
|
||||||
@@ -18,14 +18,14 @@ class MyAppState extends State<MyApp> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Load local JSON file"),
|
title: Text("Load local JSON file"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
// Use future builder and DefaultAssetBundle to load the local JSON file
|
// Use future builder and DefaultAssetBundle to load the local JSON file
|
||||||
child: new FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: DefaultAssetBundle
|
future: DefaultAssetBundle
|
||||||
.of(context)
|
.of(context)
|
||||||
.loadString('data_repo/starwars_data.json'),
|
.loadString('data_repo/starwars_data.json'),
|
||||||
@@ -33,25 +33,25 @@ class MyAppState extends State<MyApp> {
|
|||||||
// Decode the JSON
|
// Decode the JSON
|
||||||
var new_data = json.decode(snapshot.data.toString());
|
var new_data = json.decode(snapshot.data.toString());
|
||||||
|
|
||||||
return new ListView.builder(
|
return ListView.builder(
|
||||||
// Build the ListView
|
// Build the ListView
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return new Card(
|
return Card(
|
||||||
child: new Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text("Name: " + new_data[index]['name']),
|
Text("Name: " + new_data[index]['name']),
|
||||||
new Text("Height: " + new_data[index]['height']),
|
Text("Height: " + new_data[index]['height']),
|
||||||
new Text("Mass: " + new_data[index]['mass']),
|
Text("Mass: " + new_data[index]['mass']),
|
||||||
new Text(
|
Text(
|
||||||
"Hair Color: " + new_data[index]['hair_color']),
|
"Hair Color: " + new_data[index]['hair_color']),
|
||||||
new Text(
|
Text(
|
||||||
"Skin Color: " + new_data[index]['skin_color']),
|
"Skin Color: " + new_data[index]['skin_color']),
|
||||||
new Text(
|
Text(
|
||||||
"Eye Color: " + new_data[index]['eye_color']),
|
"Eye Color: " + new_data[index]['eye_color']),
|
||||||
new Text(
|
Text(
|
||||||
"Birth Year: " + new_data[index]['birth_year']),
|
"Birth Year: " + new_data[index]['birth_year']),
|
||||||
new Text("Gender: " + new_data[index]['gender'])
|
Text("Gender: " + new_data[index]['gender'])
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import 'package:navigation_drawer/screens/home.dart';
|
|||||||
import 'package:navigation_drawer/screens/settings.dart';
|
import 'package:navigation_drawer/screens/settings.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: new HomeScreen(), // route for home is '/' implicitly
|
home: HomeScreen(), // route for home is '/' implicitly
|
||||||
routes: <String, WidgetBuilder>{
|
routes: <String, WidgetBuilder>{
|
||||||
// define the routes
|
// define the routes
|
||||||
SettingsScreen.routeName: (BuildContext context) => new SettingsScreen(),
|
SettingsScreen.routeName: (BuildContext context) => SettingsScreen(),
|
||||||
AccountScreen.routeName: (BuildContext context) => new AccountScreen(),
|
AccountScreen.routeName: (BuildContext context) => AccountScreen(),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ class AccountScreen extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Account"),
|
title: Text("Account"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Text("Account Screen"),
|
child: Text("Account Screen"),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,23 @@ import 'package:navigation_drawer/screens/settings.dart';
|
|||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
HomeScreenState createState() => new HomeScreenState();
|
HomeScreenState createState() => HomeScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class HomeScreenState extends State<HomeScreen> {
|
class HomeScreenState extends State<HomeScreen> {
|
||||||
Drawer getNavDrawer(BuildContext context) {
|
Drawer getNavDrawer(BuildContext context) {
|
||||||
var headerChild = new DrawerHeader(child: new Text("Header"));
|
var headerChild = DrawerHeader(child: Text("Header"));
|
||||||
var aboutChild = new AboutListTile(
|
var aboutChild = AboutListTile(
|
||||||
child: new Text("About"),
|
child: Text("About"),
|
||||||
applicationName: "Application Name",
|
applicationName: "Application Name",
|
||||||
applicationVersion: "v1.0.0",
|
applicationVersion: "v1.0.0",
|
||||||
applicationIcon: new Icon(Icons.adb),
|
applicationIcon: Icon(Icons.adb),
|
||||||
icon: new Icon(Icons.info));
|
icon: Icon(Icons.info));
|
||||||
|
|
||||||
ListTile getNavItem(var icon, String s, String routeName) {
|
ListTile getNavItem(var icon, String s, String routeName) {
|
||||||
return new ListTile(
|
return ListTile(
|
||||||
leading: new Icon(icon),
|
leading: Icon(icon),
|
||||||
title: new Text(s),
|
title: Text(s),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
// pop closes the drawer
|
// pop closes the drawer
|
||||||
@@ -40,22 +40,22 @@ class HomeScreenState extends State<HomeScreen> {
|
|||||||
aboutChild
|
aboutChild
|
||||||
];
|
];
|
||||||
|
|
||||||
ListView listView = new ListView(children: myNavChildren);
|
ListView listView = ListView(children: myNavChildren);
|
||||||
|
|
||||||
return new Drawer(
|
return Drawer(
|
||||||
child: listView,
|
child: listView,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Navigation Drawer Example"),
|
title: Text("Navigation Drawer Example"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Text("Home Screen"),
|
child: Text("Home Screen"),
|
||||||
)),
|
)),
|
||||||
// Set the nav drawer
|
// Set the nav drawer
|
||||||
drawer: getNavDrawer(context),
|
drawer: getNavDrawer(context),
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ class SettingsScreen extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Settings"),
|
title: Text("Settings"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Text("Settings Screen"),
|
child: Text("Settings Screen"),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Disable the debug flag
|
// Disable the debug flag
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
// Home
|
// Home
|
||||||
home: new MyHome()));
|
home: MyHome()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyHome extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyHomeState createState() {
|
MyHomeState createState() {
|
||||||
return new MyHomeState();
|
return MyHomeState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,31 +67,31 @@ class MyHomeState extends State<MyHome> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text(nameOfApp),
|
title: Text(nameOfApp),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(
|
Text(
|
||||||
'$counter',
|
'$counter',
|
||||||
textScaleFactor: 10.0,
|
textScaleFactor: 10.0,
|
||||||
),
|
),
|
||||||
new Padding(padding: new EdgeInsets.all(10.0)),
|
Padding(padding: EdgeInsets.all(10.0)),
|
||||||
new RaisedButton(
|
RaisedButton(
|
||||||
onPressed: _onIncrementHit,
|
onPressed: _onIncrementHit,
|
||||||
child: new Text('Increment Counter')),
|
child: Text('Increment Counter')),
|
||||||
new Padding(padding: new EdgeInsets.all(10.0)),
|
Padding(padding: EdgeInsets.all(10.0)),
|
||||||
new RaisedButton(
|
RaisedButton(
|
||||||
onPressed: _onDecrementHit,
|
onPressed: _onDecrementHit,
|
||||||
child: new Text('Decrement Counter')),
|
child: Text('Decrement Counter')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Simple Material App",
|
title: "Simple Material App",
|
||||||
// Home
|
// Home
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Simple Material App"),
|
title: Text("Simple Material App"),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
// Add Text
|
// Add Text
|
||||||
child: new Text("Hello World!"),
|
child: Text("Hello World!"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyButton(),
|
home: MyButton(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyButton extends StatefulWidget {
|
class MyButton extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyButtonState createState() {
|
MyButtonState createState() {
|
||||||
return new MyButtonState();
|
return MyButtonState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,22 +27,22 @@ class MyButtonState extends State<MyButton> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Stateful Widget"),
|
title: Text("Stateful Widget"),
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(displayedString, style: new TextStyle(fontSize: 40.0)),
|
Text(displayedString, style: TextStyle(fontSize: 40.0)),
|
||||||
new Padding(padding: new EdgeInsets.all(10.0)),
|
Padding(padding: EdgeInsets.all(10.0)),
|
||||||
new RaisedButton(
|
RaisedButton(
|
||||||
child: new Text(
|
child: Text(
|
||||||
"Press me",
|
"Press me",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
onPressed: onPressOfButton,
|
onPressed: onPressOfButton,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyApp(),
|
home: MyApp(),
|
||||||
// Define the theme, set the primary swatch
|
// 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 myTextSize = 30.0;
|
||||||
final double myIconSize = 40.0;
|
final double myIconSize = 40.0;
|
||||||
final TextStyle myTextStyle =
|
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
|
// Makes the cards stretch in horizontal axis
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Setup the card
|
// Setup the card
|
||||||
new MyCard(
|
MyCard(
|
||||||
// Setup the text
|
// Setup the text
|
||||||
title: new Text(
|
title: Text(
|
||||||
"Favorite",
|
"Favorite",
|
||||||
style: myTextStyle,
|
style: myTextStyle,
|
||||||
),
|
),
|
||||||
// Setup the icon
|
// Setup the icon
|
||||||
icon:
|
icon:
|
||||||
new Icon(Icons.favorite, size: myIconSize, color: Colors.red)),
|
Icon(Icons.favorite, size: myIconSize, color: Colors.red)),
|
||||||
new MyCard(
|
MyCard(
|
||||||
title: new Text(
|
title: Text(
|
||||||
"Alarm",
|
"Alarm",
|
||||||
style: myTextStyle,
|
style: myTextStyle,
|
||||||
),
|
),
|
||||||
icon: new Icon(Icons.alarm, size: myIconSize, color: Colors.blue)),
|
icon: Icon(Icons.alarm, size: myIconSize, color: Colors.blue)),
|
||||||
new MyCard(
|
MyCard(
|
||||||
title: new Text(
|
title: Text(
|
||||||
"Airport Shuttle",
|
"Airport Shuttle",
|
||||||
style: myTextStyle,
|
style: myTextStyle,
|
||||||
),
|
),
|
||||||
icon: new Icon(Icons.airport_shuttle,
|
icon: Icon(Icons.airport_shuttle,
|
||||||
size: myIconSize, color: Colors.amber)),
|
size: myIconSize, color: Colors.amber)),
|
||||||
new MyCard(
|
MyCard(
|
||||||
title: new Text(
|
title: Text(
|
||||||
"Done",
|
"Done",
|
||||||
style: myTextStyle,
|
style: myTextStyle,
|
||||||
),
|
),
|
||||||
icon: new Icon(Icons.done, size: myIconSize, color: Colors.green)),
|
icon: Icon(Icons.done, size: myIconSize, color: Colors.green)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Stateless Widget"),
|
title: Text("Stateless Widget"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Sets the padding in the main container
|
// Sets the padding in the main container
|
||||||
padding: const EdgeInsets.only(bottom: 2.0),
|
padding: const EdgeInsets.only(bottom: 2.0),
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new SingleChildScrollView(child: column),
|
child: SingleChildScrollView(child: column),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -74,17 +74,17 @@ class MyCard extends StatelessWidget {
|
|||||||
final Widget icon;
|
final Widget icon;
|
||||||
final Widget title;
|
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});
|
MyCard({this.title, this.icon});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Container(
|
return Container(
|
||||||
padding: const EdgeInsets.only(bottom: 1.0),
|
padding: const EdgeInsets.only(bottom: 1.0),
|
||||||
child: new Card(
|
child: Card(
|
||||||
child: new Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: new Column(
|
child: Column(
|
||||||
children: <Widget>[this.title, this.icon],
|
children: <Widget>[this.title, this.icon],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import '../lib/main.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(new MyApp());
|
await tester.pumpWidget(MyApp());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(title: 'Tip Calculator', home: new TipCalculator()));
|
runApp(MaterialApp(title: 'Tip Calculator', home: TipCalculator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class TipCalculator extends StatelessWidget {
|
class TipCalculator extends StatelessWidget {
|
||||||
@@ -11,7 +11,7 @@ class TipCalculator extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Create first input field
|
// Create first input field
|
||||||
TextField billAmountField = new TextField(
|
TextField billAmountField = TextField(
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
try {
|
try {
|
||||||
@@ -20,12 +20,12 @@ class TipCalculator extends StatelessWidget {
|
|||||||
billAmount = 0.0;
|
billAmount = 0.0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
decoration: new InputDecoration(labelText: "Bill amount(\$)"),
|
decoration: InputDecoration(labelText: "Bill amount(\$)"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create another input field
|
// Create another input field
|
||||||
TextField tipPercentageField = new TextField(
|
TextField tipPercentageField = TextField(
|
||||||
decoration: new InputDecoration(labelText: "Tip %", hintText: "15"),
|
decoration: InputDecoration(labelText: "Tip %", hintText: "15"),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
try {
|
try {
|
||||||
@@ -36,30 +36,30 @@ class TipCalculator extends StatelessWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create button
|
// Create button
|
||||||
RaisedButton calculateButton = new RaisedButton(
|
RaisedButton calculateButton = RaisedButton(
|
||||||
child: new Text("Calculate"),
|
child: Text("Calculate"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Calculate tip and total
|
// Calculate tip and total
|
||||||
double calculatedTip = billAmount * tipPercentage / 100.0;
|
double calculatedTip = billAmount * tipPercentage / 100.0;
|
||||||
double total = billAmount + calculatedTip;
|
double total = billAmount + calculatedTip;
|
||||||
|
|
||||||
// Generate dialog
|
// Generate dialog
|
||||||
AlertDialog dialog = new AlertDialog(
|
AlertDialog dialog = AlertDialog(
|
||||||
content: new Text("Tip: \$$calculatedTip \n"
|
content: Text("Tip: \$$calculatedTip \n"
|
||||||
"Total: \$$total"));
|
"Total: \$$total"));
|
||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
showDialog(context: context, builder: (BuildContext context) => dialog);
|
showDialog(context: context, builder: (BuildContext context) => dialog);
|
||||||
});
|
});
|
||||||
|
|
||||||
Container container = new Container(
|
Container container = Container(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: new Column(
|
child: Column(
|
||||||
children: [billAmountField, tipPercentageField, calculateButton]));
|
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;
|
return scaffold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyHome(),
|
home: MyHome(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyHome extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyHomeState createState() => new MyHomeState();
|
MyHomeState createState() => MyHomeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHomeState extends State<MyHome> {
|
class MyHomeState extends State<MyHome> {
|
||||||
// Generate dialog
|
// Generate dialog
|
||||||
AlertDialog dialog = new AlertDialog(
|
AlertDialog dialog = AlertDialog(
|
||||||
content: new Text(
|
content: Text(
|
||||||
"Hello World!",
|
"Hello World!",
|
||||||
style: new TextStyle(fontSize: 30.0),
|
style: TextStyle(fontSize: 30.0),
|
||||||
));
|
));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Using Alert Dialog"),
|
title: Text("Using Alert Dialog"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new RaisedButton(
|
child: RaisedButton(
|
||||||
child: new Text("Hit to alert!"),
|
child: Text("Hit to alert!"),
|
||||||
// On press of the button
|
// On press of the button
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Show dialog
|
// Show dialog
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import 'package:using_bottom_nav_bar/tabs/second.dart';
|
|||||||
import 'package:using_bottom_nav_bar/tabs/third.dart';
|
import 'package:using_bottom_nav_bar/tabs/third.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Using Tabs",
|
title: "Using Tabs",
|
||||||
// Home
|
// Home
|
||||||
home: new MyHome()));
|
home: MyHome()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyHome extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyHomeState createState() => new MyHomeState();
|
MyHomeState createState() => MyHomeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SingleTickerProviderStateMixin is used for animation
|
// SingleTickerProviderStateMixin is used for animation
|
||||||
@@ -26,7 +26,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
// Initialize the Tab Controller
|
// Initialize the Tab Controller
|
||||||
controller = new TabController(length: 3, vsync: this);
|
controller = TabController(length: 3, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -38,37 +38,37 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Using Bottom Navigation Bar"),
|
title: Text("Using Bottom Navigation Bar"),
|
||||||
// Set the background color of the App Bar
|
// Set the background color of the App Bar
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
),
|
),
|
||||||
// Set the TabBar view as the body of the Scaffold
|
// Set the TabBar view as the body of the Scaffold
|
||||||
body: new TabBarView(
|
body: TabBarView(
|
||||||
// Add tabs as widgets
|
// Add tabs as widgets
|
||||||
children: <Widget>[new FirstTab(), new SecondTab(), new ThirdTab()],
|
children: <Widget>[FirstTab(), SecondTab(), ThirdTab()],
|
||||||
// set the controller
|
// set the controller
|
||||||
controller: controller,
|
controller: controller,
|
||||||
),
|
),
|
||||||
// Set the bottom navigation bar
|
// Set the bottom navigation bar
|
||||||
bottomNavigationBar: new Material(
|
bottomNavigationBar: Material(
|
||||||
// set the color of the bottom navigation bar
|
// set the color of the bottom navigation bar
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
// set the tab bar as the child of bottom navigation bar
|
// set the tab bar as the child of bottom navigation bar
|
||||||
child: new TabBar(
|
child: TabBar(
|
||||||
tabs: <Tab>[
|
tabs: <Tab>[
|
||||||
new Tab(
|
Tab(
|
||||||
// set icon to the tab
|
// set icon to the tab
|
||||||
icon: new Icon(Icons.favorite),
|
icon: Icon(Icons.favorite),
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab(
|
||||||
icon: new Icon(Icons.adb),
|
icon: Icon(Icons.adb),
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab(
|
||||||
icon: new Icon(Icons.airport_shuttle),
|
icon: Icon(Icons.airport_shuttle),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
// setup the controller
|
// setup the controller
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
|
|||||||
class FirstTab extends StatelessWidget {
|
class FirstTab extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.favorite,
|
Icons.favorite,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
new Text(
|
Text(
|
||||||
"First Tab",
|
"First Tab",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
|
|||||||
class SecondTab extends StatelessWidget {
|
class SecondTab extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.adb,
|
Icons.adb,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
new Text(
|
Text(
|
||||||
"Second Tab",
|
"Second Tab",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
|
|||||||
class ThirdTab extends StatelessWidget {
|
class ThirdTab extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.orange,
|
backgroundColor: Colors.orange,
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.airport_shuttle,
|
Icons.airport_shuttle,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
new Text(
|
Text(
|
||||||
"Third Tab",
|
"Third Tab",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ import 'package:flutter/material.dart';
|
|||||||
import './utils.dart' as utils;
|
import './utils.dart' as utils;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Using Custom Fonts",
|
title: "Using Custom Fonts",
|
||||||
// Home
|
// Home
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Using Custom Fonts"),
|
title: Text("Using Custom Fonts"),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
// Add Text
|
// 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
|
// Center align text
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
// set a text style which defines a custom font
|
// set a text style which defines a custom font
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyEditText(),
|
home: MyEditText(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyEditText extends StatefulWidget {
|
class MyEditText extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyEditTextState createState() => new MyEditTextState();
|
MyEditTextState createState() => MyEditTextState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyEditTextState extends State<MyEditText> {
|
class MyEditTextState extends State<MyEditText> {
|
||||||
String results = "";
|
String results = "";
|
||||||
|
|
||||||
final TextEditingController controller = new TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Using EditText"),
|
title: Text("Using EditText"),
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new TextField(
|
TextField(
|
||||||
decoration: new InputDecoration(hintText: "Enter text here..."),
|
decoration: InputDecoration(hintText: "Enter text here..."),
|
||||||
onSubmitted: (String str) {
|
onSubmitted: (String str) {
|
||||||
setState(() {
|
setState(() {
|
||||||
results = results + "\n" + str;
|
results = results + "\n" + str;
|
||||||
@@ -39,7 +39,7 @@ class MyEditTextState extends State<MyEditText> {
|
|||||||
},
|
},
|
||||||
controller: controller,
|
controller: controller,
|
||||||
),
|
),
|
||||||
new Text(results)
|
Text(results)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,28 +3,28 @@ import 'package:flutter/material.dart';
|
|||||||
import './utils.dart' as utils;
|
import './utils.dart' as utils;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Using Gradient",
|
title: "Using Gradient",
|
||||||
// Home
|
// Home
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Using Gradient"),
|
title: Text("Using Gradient"),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Center the content
|
// Center the content
|
||||||
child: new Center(
|
child: Center(
|
||||||
// Add Text
|
// Add Text
|
||||||
child: new Text(
|
child: Text(
|
||||||
"Hello World!",
|
"Hello World!",
|
||||||
style: new TextStyle(color: Colors.white),
|
style: TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Set background
|
// Set background
|
||||||
decoration: new BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
// Add Gradient
|
// Add Gradient
|
||||||
gradient: utils.getCustomGradient())))));
|
gradient: utils.getCustomGradient())))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
LinearGradient getCustomGradient() {
|
LinearGradient getCustomGradient() {
|
||||||
// Define a Linear Gradient
|
// Define a Linear Gradient
|
||||||
return new LinearGradient(
|
return LinearGradient(
|
||||||
colors: [Colors.pink, Colors.blueAccent],
|
colors: [Colors.pink, Colors.blueAccent],
|
||||||
begin: const FractionalOffset(0.0, 0.0),
|
begin: const FractionalOffset(0.0, 0.0),
|
||||||
end: const FractionalOffset(0.6, 0.0),
|
end: const FractionalOffset(0.6, 0.0),
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
home: new MyGetHttpData(),
|
home: MyGetHttpData(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a stateful widget
|
// Create a stateful widget
|
||||||
class MyGetHttpData extends StatefulWidget {
|
class MyGetHttpData extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyGetHttpDataState createState() => new MyGetHttpDataState();
|
MyGetHttpDataState createState() => MyGetHttpDataState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the state for our stateful widget
|
// Create the state for our stateful widget
|
||||||
@@ -44,27 +44,27 @@ class MyGetHttpDataState extends State<MyGetHttpData> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Retrieve JSON Data via HTTP GET"),
|
title: Text("Retrieve JSON Data via HTTP GET"),
|
||||||
),
|
),
|
||||||
// Create a Listview and load the data when available
|
// Create a Listview and load the data when available
|
||||||
body: new ListView.builder(
|
body: ListView.builder(
|
||||||
itemCount: data == null ? 0 : data.length,
|
itemCount: data == null ? 0 : data.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return new Container(
|
return Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// Stretch the cards in horizontal axis
|
// Stretch the cards in horizontal axis
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Card(
|
Card(
|
||||||
child: new Container(
|
child: Container(
|
||||||
child: new Text(
|
child: Text(
|
||||||
// Read the name field value and set it in the Text widget
|
// Read the name field value and set it in the Text widget
|
||||||
data[index]['name'],
|
data[index]['name'],
|
||||||
// set some style to text
|
// set some style to text
|
||||||
style: new TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20.0, color: Colors.lightBlueAccent),
|
fontSize: 20.0, color: Colors.lightBlueAccent),
|
||||||
),
|
),
|
||||||
// added padding
|
// added padding
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ class ContactPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(body: new ContactsList(_buildContactList()));
|
return Scaffold(body: ContactsList(_buildContactList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ class ContactsList extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new ListView(
|
return ListView(
|
||||||
padding: new EdgeInsets.symmetric(vertical: 8.0),
|
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||||
children: _buildContactsList(),
|
children: _buildContactsList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ContactListItem> _buildContactsList() {
|
List<ContactListItem> _buildContactsList() {
|
||||||
return _contactModal
|
return _contactModal
|
||||||
.map((contact) => new ContactListItem(contact))
|
.map((contact) => ContactListItem(contact))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ class ContactListItem extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new ListTile(
|
return ListTile(
|
||||||
leading: new CircleAvatar(child: new Text(_contactModal.fullName[0])),
|
leading: CircleAvatar(child: Text(_contactModal.fullName[0])),
|
||||||
title: new Text(_contactModal.fullName),
|
title: Text(_contactModal.fullName),
|
||||||
subtitle: new Text(_contactModal.email));
|
subtitle: Text(_contactModal.email));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:using_listview/contact_page.dart';
|
import 'package:using_listview/contact_page.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: new Scaffold(
|
home: Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Using Listview"),
|
title: Text("Using Listview"),
|
||||||
),
|
),
|
||||||
body: new ContactPage(),
|
body: ContactPage(),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(home: new ContactPage(), debugShowCheckedModeBanner: false,));
|
runApp(MaterialApp(home: ContactPage(), debugShowCheckedModeBanner: false,));
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactPage extends StatelessWidget {
|
class ContactPage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
title: new Text("Using SnackBar"),
|
title: Text("Using SnackBar"),
|
||||||
),
|
),
|
||||||
body: new Center(
|
body: Center(
|
||||||
child: new MyButton(),
|
child: MyButton(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -21,23 +21,23 @@ class ContactPage extends StatelessWidget {
|
|||||||
class MyButton extends StatelessWidget {
|
class MyButton extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new RaisedButton(
|
return RaisedButton(
|
||||||
child: new Text('Show SnackBar'),
|
child: Text('Show SnackBar'),
|
||||||
// On pressing the raised button
|
// On pressing the raised button
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// show snackbar
|
// show snackbar
|
||||||
Scaffold.of(context).showSnackBar(new SnackBar(
|
Scaffold.of(context).showSnackBar(SnackBar(
|
||||||
// set content of snackbar
|
// set content of snackbar
|
||||||
content: new Text("Hello! I am SnackBar :)"),
|
content: Text("Hello! I am SnackBar :)"),
|
||||||
// set duration
|
// set duration
|
||||||
duration: new Duration(seconds: 3),
|
duration: Duration(seconds: 3),
|
||||||
// set the action
|
// set the action
|
||||||
action: new SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: "Hit Me (Action)",
|
label: "Hit Me (Action)",
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// When action button is pressed, show another snackbar
|
// When action button is pressed, show another snackbar
|
||||||
Scaffold.of(context).showSnackBar(new SnackBar(
|
Scaffold.of(context).showSnackBar(SnackBar(
|
||||||
content: new Text(
|
content: Text(
|
||||||
"Hello! I am shown becoz you pressed Action :)"),
|
"Hello! I am shown becoz you pressed Action :)"),
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Simple Material App",
|
title: "Simple Material App",
|
||||||
// Home
|
// Home
|
||||||
home: new MyHome()));
|
home: MyHome()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyHome extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyHomeState createState() => new MyHomeState();
|
MyHomeState createState() => MyHomeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHomeState extends State<MyHome> {
|
class MyHomeState extends State<MyHome> {
|
||||||
// init the step to 0th position
|
// init the step to 0th position
|
||||||
int current_step = 0;
|
int current_step = 0;
|
||||||
List<Step> my_steps = [
|
List<Step> my_steps = [
|
||||||
new Step(
|
Step(
|
||||||
// Title of the 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, it can be any widget here. Using basic Text for this example
|
||||||
content: new Text("Hello!"),
|
content: Text("Hello!"),
|
||||||
isActive: true),
|
isActive: true),
|
||||||
new Step(
|
Step(
|
||||||
title: new Text("Step 2"),
|
title: Text("Step 2"),
|
||||||
content: new Text("World!"),
|
content: Text("World!"),
|
||||||
// You can change the style of the step icon i.e number, editing, etc.
|
// You can change the style of the step icon i.e number, editing, etc.
|
||||||
state: StepState.editing,
|
state: StepState.editing,
|
||||||
isActive: true),
|
isActive: true),
|
||||||
new Step(
|
Step(
|
||||||
title: new Text("Step 3"),
|
title: Text("Step 3"),
|
||||||
content: new Text("Hello World!"),
|
content: Text("Hello World!"),
|
||||||
isActive: true),
|
isActive: true),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Simple Material App"),
|
title: Text("Simple Material App"),
|
||||||
),
|
),
|
||||||
// Body
|
// Body
|
||||||
body: new Container(
|
body: Container(
|
||||||
child: new Stepper(
|
child: Stepper(
|
||||||
// Using a variable here for handling the currentStep
|
// Using a variable here for handling the currentStep
|
||||||
currentStep: this.current_step,
|
currentStep: this.current_step,
|
||||||
// List the steps you would like to have
|
// List the steps you would like to have
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import 'package:using_tabs/tabs/second.dart';
|
|||||||
import 'package:using_tabs/tabs/third.dart';
|
import 'package:using_tabs/tabs/third.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
// Title
|
// Title
|
||||||
title: "Using Tabs",
|
title: "Using Tabs",
|
||||||
// Home
|
// Home
|
||||||
home: new MyHome()));
|
home: MyHome()));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyHome extends StatefulWidget {
|
class MyHome extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
MyHomeState createState() => new MyHomeState();
|
MyHomeState createState() => MyHomeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SingleTickerProviderStateMixin is used for animation
|
// SingleTickerProviderStateMixin is used for animation
|
||||||
@@ -29,7 +29,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
// Initialize the Tab Controller
|
// Initialize the Tab Controller
|
||||||
controller = new TabController(length: 3, vsync: this);
|
controller = TabController(length: 3, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -40,17 +40,17 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TabBar getTabBar() {
|
TabBar getTabBar() {
|
||||||
return new TabBar(
|
return TabBar(
|
||||||
tabs: <Tab>[
|
tabs: <Tab>[
|
||||||
new Tab(
|
Tab(
|
||||||
// set icon to the tab
|
// set icon to the tab
|
||||||
icon: new Icon(Icons.favorite),
|
icon: Icon(Icons.favorite),
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab(
|
||||||
icon: new Icon(Icons.adb),
|
icon: Icon(Icons.adb),
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab(
|
||||||
icon: new Icon(Icons.airport_shuttle),
|
icon: Icon(Icons.airport_shuttle),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
// setup the controller
|
// setup the controller
|
||||||
@@ -59,7 +59,7 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TabBarView getTabBarView(var tabs) {
|
TabBarView getTabBarView(var tabs) {
|
||||||
return new TabBarView(
|
return TabBarView(
|
||||||
// Add tabs as widgets
|
// Add tabs as widgets
|
||||||
children: tabs,
|
children: tabs,
|
||||||
// set the controller
|
// set the controller
|
||||||
@@ -72,16 +72,16 @@ class MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
|
|||||||
*/
|
*/
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// Appbar
|
// Appbar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// Title
|
// Title
|
||||||
title: new Text("Using Tabs"),
|
title: Text("Using Tabs"),
|
||||||
// Set the background color of the App Bar
|
// Set the background color of the App Bar
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
// Set the bottom property of the Appbar to include a Tab Bar
|
// Set the bottom property of the Appbar to include a Tab Bar
|
||||||
bottom: getTabBar()),
|
bottom: getTabBar()),
|
||||||
// Set the TabBar view as the body of the Scaffold
|
// 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()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
|
|||||||
class First extends StatelessWidget {
|
class First extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Container(
|
return Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.favorite,
|
Icons.favorite,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
),
|
),
|
||||||
new Text("First Tab")
|
Text("First Tab")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
|
|||||||
class Second extends StatelessWidget {
|
class Second extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Container(
|
return Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.adb,
|
Icons.adb,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.green,
|
color: Colors.green,
|
||||||
),
|
),
|
||||||
new Text("Second Tab")
|
Text("Second Tab")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ import 'package:flutter/material.dart';
|
|||||||
class Third extends StatelessWidget {
|
class Third extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Container(
|
return Container(
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Column(
|
child: Column(
|
||||||
// center the children
|
// center the children
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Icon(
|
Icon(
|
||||||
Icons.airport_shuttle,
|
Icons.airport_shuttle,
|
||||||
size: 160.0,
|
size: 160.0,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
),
|
),
|
||||||
new Text("Third Tab")
|
Text("Third Tab")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
runApp(MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: new MyHome(),
|
home: MyHome(),
|
||||||
// Set the theme's primary color, accent color,
|
// Set the theme's primary color, accent color,
|
||||||
theme: new ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.green,
|
primarySwatch: Colors.green,
|
||||||
accentColor: Colors.lightGreenAccent,
|
accentColor: Colors.lightGreenAccent,
|
||||||
// Set background color
|
// Set background color
|
||||||
@@ -17,20 +17,20 @@ void main() {
|
|||||||
class MyHome extends StatelessWidget {
|
class MyHome extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return Scaffold(
|
||||||
// AppBar
|
// AppBar
|
||||||
appBar: new AppBar(
|
appBar: AppBar(
|
||||||
// AppBar Title
|
// AppBar Title
|
||||||
title: new Text("Using Theme"),
|
title: Text("Using Theme"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
body: Container(
|
||||||
// Another way to set the background color
|
// Another way to set the background color
|
||||||
decoration: new BoxDecoration(color: Colors.black87),
|
decoration: BoxDecoration(color: Colors.black87),
|
||||||
child: new Center(
|
child: Center(
|
||||||
child: new Container(
|
child: Container(
|
||||||
// use the theme accent color as background color for this widget
|
// use the theme accent color as background color for this widget
|
||||||
color: Theme.of(context).accentColor,
|
color: Theme.of(context).accentColor,
|
||||||
child: new Text(
|
child: Text(
|
||||||
'Hello World!',
|
'Hello World!',
|
||||||
// Set text style as per theme
|
// Set text style as per theme
|
||||||
style: Theme.of(context).textTheme.title,
|
style: Theme.of(context).textTheme.title,
|
||||||
|
|||||||
Reference in New Issue
Block a user