Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 354f335

Browse files
committedDec 18, 2018
feat: add tabbar
1 parent c151a93 commit 354f335

File tree

7 files changed

+252
-42
lines changed

7 files changed

+252
-42
lines changed
 

‎lib/constants.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const String ENV = "test";
2+
const String TEST = "TEST";
3+
const String HOME = "HOME";
4+
const String PERSONAL = "PERSONAL";
5+
const String TEST_URL = "https://www.baidu.com";
6+
const String TEST_TITLE = "Baidu";
7+
const String WEBVIEW = "Webview";
8+
const String USERNAME_TIPS = "please input username";
9+
const String PASSWORD_TIPS = "please input password";
10+
const String COLOR_1 = "#00bcd4";
11+
const String COLOR_2 = "#ff4081";
12+
const String DATAHUB_HOST = "http://localhost:7001";
13+
const String DATAHUB_HUBNAME_1 = "bootstrap";

‎lib/main.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22

33
import 'page/home.dart';
44
import 'page/login.dart';
5+
import 'page/list.dart';
56

67
void main() => runApp(MyApp());
78

@@ -11,21 +12,25 @@ class MyApp extends StatelessWidget {
1112
Widget build(BuildContext context) {
1213
return MaterialApp(
1314
title: 'Flutter Demo',
14-
theme: ThemeData(
15-
primarySwatch: Colors.blue,
16-
),
1715
home: LoginPage(title: 'Home Page'),
16+
debugShowCheckedModeBanner: true,
17+
debugShowMaterialGrid: false,
1818
onGenerateRoute: (RouteSettings settings) {
1919
switch (settings.name) {
2020
case '/home':
2121
return new MyCustomRoute(
22-
builder: (_) => HomePage(title: 'Home Page'),
22+
builder: (_) => HomePage(),
2323
settings: settings,
2424
);
2525

2626
case '/login':
2727
return new MyCustomRoute(
28-
builder: (_) => LoginPage(title: 'Login Page'),
28+
builder: (_) => LoginPage(),
29+
settings: settings,
30+
);
31+
case '/list':
32+
return new MyCustomRoute(
33+
builder: (_) => ListPage(),
2934
settings: settings,
3035
);
3136
}
@@ -44,4 +49,4 @@ class MyCustomRoute<T> extends MaterialPageRoute<T> {
4449
if (settings.isInitialRoute) return child;
4550
return new FadeTransition(opacity: animation, child: child);
4651
}
47-
}
52+
}

‎lib/page/home.dart

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,125 @@
1-
21
import 'package:flutter/material.dart';
2+
import 'dart:io' show Platform;
3+
4+
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
5+
6+
import '../constants.dart' as CONSTANTS;
7+
import '../utils.dart' as Utils;
38

49
class HomePage extends StatefulWidget {
510
HomePage({Key key, this.title}) : super(key: key);
611

712
final String title;
813

914
@override
10-
HomePageState createState() => HomePageState();
15+
State<StatefulWidget> createState() {
16+
return HomePageState();
17+
}
1118
}
1219

1320
class HomePageState extends State<HomePage> {
21+
int _currentIndex = 0;
22+
var a = WebviewScaffold(
23+
url: "https://www.youku.com",
24+
hidden: true,
25+
);
26+
27+
var b = WebviewScaffold(
28+
url: "https://www.baidu.com",
29+
hidden: true,
30+
);
1431
@override
1532
Widget build(BuildContext context) {
33+
String os = Platform.operatingSystem;
34+
String osString = '${os[0].toUpperCase()}${os.substring(1)}';
35+
36+
final List<Widget> _children = [
37+
a,
38+
b,
39+
WebviewScaffold(
40+
url: CONSTANTS.TEST_URL,
41+
hidden: true,
42+
withLocalStorage: true,
43+
),
44+
WebviewScaffold(
45+
url: CONSTANTS.TEST_URL,
46+
hidden: true,
47+
withLocalStorage: true,
48+
),
49+
];
1650
return Scaffold(
17-
body: Center(
51+
appBar: new AppBar(
52+
automaticallyImplyLeading: false,
53+
elevation: 0.0,
54+
title: new Text(
55+
CONSTANTS.HOME,
56+
textAlign: TextAlign.center,
57+
style: new TextStyle(fontSize: 20.0, color: Colors.black),
58+
),
59+
centerTitle: true,
60+
backgroundColor: Colors.white,
61+
),
62+
body: _children[_currentIndex],
63+
/*
64+
new Container(
65+
padding: const EdgeInsets.all(20.0),
1866
child: Column(
1967
mainAxisAlignment: MainAxisAlignment.center,
2068
children: <Widget>[
2169
Text(
22-
'home',
70+
'$osString Flutter Bootstrap',
71+
style: new TextStyle(
72+
fontSize: 20.0,
73+
color: Colors.black
74+
),
2375
),
76+
new Container(
77+
width: MediaQuery.of(context).size.width,
78+
margin: const EdgeInsets.only(top: 80.0),
79+
decoration: new BoxDecoration(
80+
color: Color(Utils.getColorHexFromStr(CONSTANTS.COLOR_1)),
81+
borderRadius: new BorderRadius.circular(4.0),
82+
),
83+
child: FlatButton(
84+
child: Text(
85+
'list',
86+
textAlign: TextAlign.center,
87+
style: new TextStyle(
88+
fontSize: 20.0,
89+
color: Color(Utils.getColorHexFromStr('#ffffff'))
90+
),
91+
),
92+
onPressed: () {
93+
Navigator.pushNamed(context, '/list');
94+
}
95+
)
96+
)
2497
],
2598
),
2699
),
100+
*/
101+
102+
bottomNavigationBar: BottomNavigationBar(
103+
type: BottomNavigationBarType.fixed,
104+
items: <BottomNavigationBarItem>[
105+
BottomNavigationBarItem(
106+
icon: Icon(Icons.home), title: Text(CONSTANTS.HOME)),
107+
BottomNavigationBarItem(
108+
icon: Icon(Icons.explore), title: Text(CONSTANTS.WEBVIEW)),
109+
BottomNavigationBarItem(
110+
icon: Icon(Icons.explore), title: Text(CONSTANTS.TEST_TITLE)),
111+
BottomNavigationBarItem(
112+
icon: Icon(Icons.account_circle),
113+
title: Text(CONSTANTS.PERSONAL)),
114+
],
115+
currentIndex: _currentIndex,
116+
fixedColor: Color(Utils.getColorHexFromStr(CONSTANTS.COLOR_2)),
117+
onTap: (index) {
118+
setState(() {
119+
_currentIndex = index;
120+
});
121+
},
122+
),
27123
);
28124
}
29-
}
125+
}

‎lib/page/list.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:flutter/material.dart';
2+
3+
import '../constants.dart' as CONSTANTS;
4+
5+
class ListPage extends StatefulWidget {
6+
ListPage({Key key, this.title}) : super(key: key);
7+
8+
final String title;
9+
10+
@override
11+
ListPageState createState() => ListPageState();
12+
}
13+
14+
class ListPageState extends State<ListPage> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
appBar: new AppBar(
19+
automaticallyImplyLeading: false,
20+
elevation: 0.0,
21+
title: new Text(
22+
CONSTANTS.HOME,
23+
textAlign: TextAlign.center,
24+
style: new TextStyle(fontSize: 20.0, color: Colors.black),
25+
),
26+
centerTitle: true,
27+
backgroundColor: Colors.white,
28+
),
29+
body: new Container(
30+
padding: const EdgeInsets.all(20.0),
31+
child: Column(
32+
children: <Widget>[
33+
Text(
34+
'Flutter Bootstrap',
35+
textAlign: TextAlign.center,
36+
style: new TextStyle(fontSize: 20.0, color: Colors.black),
37+
),
38+
],
39+
),
40+
),
41+
);
42+
}
43+
}

‎lib/page/login.dart

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
21
import 'package:flutter/material.dart';
2+
import 'dart:io' show Platform;
3+
4+
import '../constants.dart' as CONSTANTS;
5+
import '../utils.dart' as Utils;
36

47
class LoginPage extends StatefulWidget {
58
LoginPage({Key key, this.title}) : super(key: key);
@@ -12,49 +15,77 @@ class LoginPage extends StatefulWidget {
1215

1316
class LoginPageState extends State<LoginPage> {
1417
GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
15-
1618
String _name;
17-
1819
String _password;
1920
@override
2021
Widget build(BuildContext context) {
22+
String os = Platform.operatingSystem;
23+
String osString = '${os[0].toUpperCase()}${os.substring(1)}';
2124
return Scaffold(
22-
body: new Container(
23-
padding: const EdgeInsets.all(36.0),
24-
child: new Form(
25-
key: _formKey,
26-
child: new Column(
27-
children: <Widget>[
28-
new TextFormField(
29-
decoration: new InputDecoration(
30-
labelText: 'Your Name',
25+
body: new Container(
26+
padding: const EdgeInsets.all(20.0),
27+
child: new Form(
28+
key: _formKey,
29+
child: new Column(
30+
children: <Widget>[
31+
new Container(
32+
margin: const EdgeInsets.symmetric(vertical: 40.0),
33+
child: new TextField(
34+
decoration: InputDecoration(
35+
border: InputBorder.none,
36+
hintText: '$osString Flutter Bootstrap',
37+
),
38+
textAlign: TextAlign.center,
39+
style: new TextStyle(
40+
fontSize: 25.0,
3141
),
32-
onSaved: (val) {
33-
_name = val;
34-
},
3542
),
36-
new TextFormField(
43+
),
44+
new Container(
45+
margin: const EdgeInsets.symmetric(vertical: 30.0),
46+
child: new TextFormField(
3747
decoration: new InputDecoration(
38-
labelText: 'Password',
48+
hintText: CONSTANTS.USERNAME_TIPS,
3949
),
40-
obscureText: true,
41-
validator: (val) {
42-
return val.length < 4 ? 'length error' : null;
43-
},
4450
onSaved: (val) {
45-
_password = val;
51+
_name = val;
4652
},
4753
),
48-
FlatButton(
49-
child: Text('login'),
50-
onPressed: () {
51-
Navigator.pushNamed(context, '/home');
52-
}
53-
)
54-
],
55-
),
54+
),
55+
new TextFormField(
56+
decoration: new InputDecoration(
57+
hintText: CONSTANTS.PASSWORD_TIPS,
58+
),
59+
obscureText: true,
60+
validator: (val) {
61+
return val.length < 0 ? 'length error' : null;
62+
},
63+
onSaved: (val) {
64+
_password = val;
65+
},
66+
),
67+
new Container(
68+
width: MediaQuery.of(context).size.width,
69+
margin: const EdgeInsets.only(top: 80.0),
70+
decoration: new BoxDecoration(
71+
color: Color(Utils.getColorHexFromStr(CONSTANTS.COLOR_1)),
72+
borderRadius: new BorderRadius.circular(4.0),
73+
),
74+
child: FlatButton(
75+
child: Text(
76+
'Login',
77+
textAlign: TextAlign.center,
78+
style: new TextStyle(
79+
fontSize: 20.0,
80+
color: Color(Utils.getColorHexFromStr('#ffffff'))),
81+
),
82+
onPressed: () {
83+
Navigator.pushNamed(context, '/home');
84+
})),
85+
],
5686
),
5787
),
88+
),
5889
);
5990
}
60-
}
91+
}

‎lib/utils.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
int getColorHexFromStr(String colorStr) {
2+
colorStr = "FF" + colorStr;
3+
colorStr = colorStr.replaceAll("#", "");
4+
int val = 0;
5+
int len = colorStr.length;
6+
for (int i = 0; i < len; i++) {
7+
int hexDigit = colorStr.codeUnitAt(i);
8+
if (hexDigit >= 48 && hexDigit <= 57) {
9+
val += (hexDigit - 48) * (1 << (4 * (len - 1 - i)));
10+
} else if (hexDigit >= 65 && hexDigit <= 70) {
11+
// A..F
12+
val += (hexDigit - 55) * (1 << (4 * (len - 1 - i)));
13+
} else if (hexDigit >= 97 && hexDigit <= 102) {
14+
// a..f
15+
val += (hexDigit - 87) * (1 << (4 * (len - 1 - i)));
16+
} else {
17+
throw new FormatException("An error occurred when converting a color");
18+
}
19+
}
20+
return val;
21+
}

‎pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ environment:
1515
dependencies:
1616
flutter:
1717
sdk: flutter
18+
flutter_webview_plugin: ^0.3.0+2
1819

1920
# The following adds the Cupertino Icons font to your application.
2021
# Use with the CupertinoIcons class for iOS style icons.

0 commit comments

Comments
 (0)
Please sign in to comment.