-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.dart
More file actions
144 lines (129 loc) · 3.59 KB
/
main.dart
File metadata and controls
144 lines (129 loc) · 3.59 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
import 'package:flutter/material.dart';
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import '../themes.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key, this.onClicked}) : super(key: key);
final VoidCallback? onClicked;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Employee App",
home: const MyHomePage(),
theme: ThemeData(
primaryColor: Colors.blue.shade900,
splashColor: Colors.blue,
textTheme: ThemeData.light().textTheme.copyWith(
headline6: const TextStyle(
fontFamily: 'Raleway-Bold',
fontSize: 20,
color: Colors.black,
),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late List<String> dummyemployees;
@override
void initState() {
super.initState();
dummyemployees = [];
addDummyEmployees();
}
addDummyEmployees() {
dummyemployees.add("Employee 1");
dummyemployees.add("Employee 2");
dummyemployees.add("Employee 3");
}
removeDummyEmployee(index) {
setState(() {
dummyemployees.removeAt(index);
});
}
Widget swipeDeleteButton() {
return Container(
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 20.0),
color: Colors.red,
child: const Icon(Icons.delete, color: Colors.white),
);
}
undoDelete(index, dummyemployee) {
setState(() {
dummyemployees.insert(index, dummyemployee);
});
}
showSnackBar(context, dummyemployee, index) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$dummyemployee deleted'),
action: SnackBarAction(
label: "undo delete",
onPressed: () {
undoDelete(index, dummyemployee);
}),
),
);
}
Widget list() {
return ListView.builder(
padding: const EdgeInsets.all(20.0),
itemCount: dummyemployees.length,
itemBuilder: (BuildContext context, int index) {
return row(context, index);
},
);
}
Widget row(context, index) {
return Dismissible(
key: Key(dummyemployees[index]),
onDismissed: (direction) {
var dummyemployee = dummyemployees[index];
showSnackBar(context, dummyemployee, index);
removeDummyEmployee(index);
},
background: swipeDeleteButton(),
child: Card(
child: ListTile(
title: Text(dummyemployees[index]),
),
),
);
}
@override
Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
final icon = isDarkMode ? Icons.light_mode : Icons.dark_mode;
return Scaffold(
appBar: AppBar(
title: const Text('Employee App'),
backgroundColor: Theme.of(context).primaryColor,
centerTitle: true,
actions: [
ThemeSwitcher(
builder: (context) => IconButton(
icon: Icon(icon),
onPressed: () {
final theme =
isDarkMode ? MyThemes.lightTheme : MyThemes.darkTheme;
final switcher = ThemeSwitcher.of(context);
switcher.changeTheme(theme: theme);
},
),
),
],
),
body: list(),
);
}
}