Skip to content

Commit 55a0494

Browse files
authored
Merge pull request #14 from edTheGuy00/03-navigation-1
@edTheGuy00 03 navigation 1
2 parents 25ee4f6 + 71d702e commit 55a0494

File tree

8 files changed

+268
-23
lines changed

8 files changed

+268
-23
lines changed

lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/page/navigation/navigation1/coordinator.dart';
23
import 'package:flutter_ui_nice/page/page_const.dart';
34
import 'const/string_const.dart';
45
import 'const/color_const.dart';
@@ -38,6 +39,8 @@ class MyApp extends StatelessWidget {
3839
FEED_PAGES[12]: (context) => FeedPageThirteen(),
3940
SHOPPING_PAGES[17]: (context) => ShopPageEighteen(),
4041
SHOPPING_PAGES[18]: (context) => ShopPageNineteen(),
42+
43+
NAVIGATION_PAGES[0]: (context) => NavigationOneCoordinator(),
4144
//FIXME there are other pages to jump with 'page_str_const.dart',there should be make by manager
4245
},
4346
onUnknownRoute: (setting) =>

lib/page/navigation/NavigationPageOne.dart

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/const/color_const.dart';
3+
4+
class HomePage extends StatelessWidget {
5+
HomePage(this.onMenuPressed);
6+
final VoidCallback onMenuPressed;
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return Container(
11+
decoration: BoxDecoration(
12+
borderRadius: BorderRadius.circular(10.0),
13+
gradient: LinearGradient(
14+
begin: Alignment.topLeft,
15+
end: Alignment.bottomRight,
16+
colors: [YELLOW, GREEN, BLUE],
17+
),
18+
boxShadow: <BoxShadow>[
19+
BoxShadow(
20+
color: Colors.black26,
21+
offset: Offset(2.0, 1.0),
22+
blurRadius: 10.0,
23+
)
24+
],
25+
),
26+
child: Center(
27+
child: RaisedButton(onPressed: onMenuPressed, child: Text("Open Menu"),),
28+
),
29+
);
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/const/color_const.dart';
3+
4+
class BackgroundCommon extends StatelessWidget {
5+
6+
BackgroundCommon({this.child, Key key}) : super(key: key);
7+
final Widget child;
8+
9+
@override
10+
Widget build(BuildContext context) => Container(
11+
decoration: BoxDecoration(
12+
gradient: LinearGradient(
13+
begin: Alignment.topLeft,
14+
end: Alignment.bottomRight,
15+
colors: [YELLOW, GREEN, BLUE],
16+
)
17+
),
18+
child: child
19+
);
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
class HomePageAnimator {
4+
HomePageAnimator(this.controller) :
5+
translateLeft = Tween(begin: 0.0, end: -200.0).animate(controller),
6+
scaleDown = Tween(begin: 1.0, end: 0.8).animate(controller);
7+
8+
final AnimationController controller;
9+
final Animation<double> translateLeft;
10+
final Animation<double> scaleDown;
11+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/page/navigation/navigation1/animations/home_page_animator.dart';
3+
import 'package:flutter_ui_nice/page/navigation/navigation1/widgets/menu_buttons.dart';
4+
import 'package:flutter_ui_nice/page/navigation/common/widgets/background_common.dart';
5+
import 'package:flutter_ui_nice/page/navigation/common/pages/home_page.dart';
6+
7+
class NavigationOneCoordinator extends StatefulWidget {
8+
@override
9+
_Coordinator createState() => _Coordinator();
10+
}
11+
12+
class _Coordinator extends State<NavigationOneCoordinator> with TickerProviderStateMixin {
13+
AnimationController _controller;
14+
HomePageAnimator _animator;
15+
16+
@override
17+
void initState() {
18+
super.initState();
19+
_controller = AnimationController(vsync: this, duration: Duration(milliseconds: 700));
20+
_animator = HomePageAnimator(_controller);
21+
}
22+
23+
_onHomePressed() => _showHome();
24+
25+
_onChatPressed() {
26+
debugPrint("Chat Pressed");
27+
}
28+
29+
_onFeedPressed() {
30+
debugPrint("Feed Pressed");
31+
}
32+
33+
_onProfilePressed() {
34+
debugPrint("Profile Pressed");
35+
}
36+
37+
_onSettingsPressed() {
38+
debugPrint("settings Pressed");
39+
}
40+
41+
@override
42+
Widget build(BuildContext context) => Material(
43+
child: BackgroundCommon(
44+
child: Stack(
45+
children: <Widget>[
46+
Positioned(
47+
bottom: 100.0,
48+
right: 50.0,
49+
child: MenuButtons(
50+
onChatPressed: _onChatPressed,
51+
onFeedPressed: _onFeedPressed,
52+
onHomePressed: _onHomePressed,
53+
onProfilePressed: _onProfilePressed,
54+
onSettingsPressed: _onSettingsPressed,
55+
),
56+
),
57+
58+
AnimatedBuilder(
59+
animation: _controller,
60+
builder: (context, widget) => Transform(
61+
alignment: Alignment.centerLeft,
62+
transform: Matrix4
63+
.translationValues(_animator.translateLeft.value, 0.0, 0.0)
64+
..scale(_animator.scaleDown.value),
65+
child: HomePage(() => _openMenu()),
66+
),
67+
),
68+
],
69+
),
70+
),
71+
);
72+
73+
Future _openMenu() async {
74+
try {
75+
await _controller.forward().orCancel;
76+
} on TickerCanceled {
77+
print("Animation Failed");
78+
}
79+
}
80+
81+
Future _showHome() async {
82+
try {
83+
await _controller.reverse().orCancel;
84+
} on TickerCanceled {
85+
print("Animation Failed");
86+
}
87+
}
88+
89+
@override
90+
void dispose() {
91+
super.dispose();
92+
_controller.dispose();
93+
}
94+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/const/color_const.dart';
3+
4+
class Button {
5+
6+
static Widget home(VoidCallback onPressed) => _buildButton(onPressed, "HOME", Icons.home);
7+
8+
static Widget chat(VoidCallback onPressed, {int notification}) => _buildButton(onPressed, "CHAT", Icons.chat, notification:
9+
notification);
10+
11+
static Widget feed(VoidCallback onPressed) => _buildButton(onPressed, "FEED", Icons.rss_feed);
12+
13+
static Widget profile(VoidCallback onPressed) => _buildButton(onPressed, "PROFILE", Icons.person);
14+
15+
static Widget settings(VoidCallback onPressed) => _buildButton(onPressed, "SETTINGS", Icons.settings);
16+
17+
static Widget _buildButton(VoidCallback onPressed, String title, IconData icon, {int notification}) {
18+
if (notification != null) {
19+
return Container(
20+
child: Stack(
21+
children: <Widget>[
22+
_button(onPressed, title, icon),
23+
Positioned(
24+
top: 0.0,
25+
right: 0.0,
26+
child: Container(
27+
decoration: BoxDecoration(
28+
shape: BoxShape.circle,
29+
color: Colors.redAccent
30+
),
31+
child: Padding(
32+
padding: const EdgeInsets.all(6.0),
33+
child: Text("$notification", style: TextStyle(color: Colors.white),),
34+
),
35+
),
36+
),
37+
],
38+
),
39+
);
40+
} else {
41+
return _button(onPressed, title, icon);
42+
}
43+
}
44+
45+
static Widget _button(VoidCallback onPressed, String title, IconData icon) => RaisedButton(
46+
color: GREEN,
47+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
48+
onPressed: onPressed,
49+
child: Padding(
50+
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 10.0),
51+
child: Row(
52+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
53+
children: <Widget>[
54+
Text(
55+
title,
56+
style: TextStyle(
57+
fontSize: 18.0,
58+
color: TEXT_BLACK,
59+
),
60+
),
61+
SizedBox(width: 5.0,),
62+
Icon(icon)
63+
],
64+
),
65+
),
66+
);
67+
68+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_ui_nice/page/navigation/navigation1/widgets/button.dart';
3+
4+
class MenuButtons extends StatelessWidget {
5+
MenuButtons({this.onHomePressed, this.onChatPressed, this.onFeedPressed, this.onProfilePressed, this
6+
.onSettingsPressed});
7+
final VoidCallback onHomePressed;
8+
final VoidCallback onChatPressed;
9+
final VoidCallback onFeedPressed;
10+
final VoidCallback onProfilePressed;
11+
final VoidCallback onSettingsPressed;
12+
13+
List<Widget> _allButtons({int notifications}) => [
14+
Padding(
15+
padding: const EdgeInsets.only(left: 10.0, right: 30.0, bottom: 20.0),
16+
child: Button.home(onHomePressed),
17+
),
18+
Padding(
19+
padding: const EdgeInsets.only(left: 50.0, bottom: 20.0),
20+
child: Button.chat(onChatPressed, notification: notifications),
21+
),
22+
Padding(
23+
padding: const EdgeInsets.only(left: 8.0, bottom: 20.0),
24+
child: Button.feed(onFeedPressed),
25+
),
26+
Padding(
27+
padding: const EdgeInsets.only(left: 50.0, bottom: 20.0),
28+
child: Button.profile(onProfilePressed),
29+
),
30+
Button.settings(onSettingsPressed)
31+
];
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return Container(
36+
child: Column(
37+
children: _allButtons(notifications: 5),
38+
),
39+
);
40+
}
41+
}

0 commit comments

Comments
 (0)