-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome_screen.dart
More file actions
152 lines (145 loc) · 4.14 KB
/
Copy pathhome_screen.dart
File metadata and controls
152 lines (145 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import 'dart:developer';
import 'package:demo_flutter/splash_screen.dart';
import 'package:demo_flutter/user_list.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class HomeScreen extends StatelessWidget {
redirectToScreen(BuildContext context, Widget widget) {
Navigator.push(context,
new MaterialPageRoute(builder: (BuildContext buildContext) => widget));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Dashboard"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () {
log("notification clicked");
},
),
IconButton(
icon: Icon(Icons.power_settings_new),
onPressed: () async {
_showLogoutConfirmationDialog(context);
},
),
],
),
drawer: getDrawerList(context),
body: getContent(),
);
}
void _logoutClick(BuildContext context) async {
SharedPreferences pref = await SharedPreferences.getInstance();
await pref.setBool("is_login", false);
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (BuildContext buildContext) => SplashScreen()));
}
Widget getContent() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(children: <Widget>[
Icon(
Icons.info,
color: Colors.blue[700],
),
Text(
'Hey!',
style: TextStyle(fontSize: 25.0, color: Colors.blue),
),
Text(
'Dashboard!',
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
),
]),
],
),
);
}
Widget getDrawerList(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
getDrawerHeader(),
ListTile(
leading: Icon(Icons.group),
title: Text('User List'),
onTap: () {
redirectToScreen(context, UserList());
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.info),
title: Text('About App'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.power_settings_new),
title: Text('Logout'),
onTap: () {
_showLogoutConfirmationDialog(context);
},
),
],
),
);
}
Widget getDrawerHeader() {
return DrawerHeader(
margin: EdgeInsets.zero,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('assets/images/furniture.jpg'))),
child: Stack(children: <Widget>[
Positioned(
bottom: 12.0,
left: 16.0,
child: Text("Jenish Jadav",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500))),
]));
}
Future<void> _showLogoutConfirmationDialog(BuildContext context) async {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Confirmation!'),
content: Text('Are you sure you want to Logout?'),
actions: <Widget>[
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Logout'),
onPressed: () {
Navigator.of(context).pop();
_logoutClick(context);
},
),
],
);
},
);
}
}