Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 97 additions & 27 deletions basic_flutter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import 'package:basic_flutter/presentation/screens/employee_dialog.dart';

import '/presentation/screens/employees_list_screen.dart';
import 'package:flutter/material.dart';
import './data/routes.dart';

import '/presentation/screens/employees_list_screen.dart';
import './data/routes.dart';
import '/presentation/screens/employee_dialog.dart';
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import '../themes.dart';

void main() {
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
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(),
routes: {
Routes.employeeListScreenRouteName: (context) =>
const EmployeesListScreen(),
Routes.employeeDialogRouteName: (context) => const EmployeeDialog(),
},
theme: ThemeData(
primaryColor: Colors.blue.shade900,
splashColor: Colors.blue,
Expand All @@ -49,26 +39,106 @@ class MyHomePage extends StatefulWidget {
}

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,
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, Routes.employeeListScreenRouteName);
},
child: const Text('Get Employees List'),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Theme.of(context).primaryColor),
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(),
);
}
}
20 changes: 20 additions & 0 deletions basic_flutter/lib/themes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

class MyThemes {
static final primary = Colors.blue.shade900;
static final primaryColor = Colors.blue.shade900;

static final darkTheme = ThemeData(
scaffoldBackgroundColor: Colors.black,
primaryColorDark: primaryColor,
colorScheme: ColorScheme.dark(primary: primary),
dividerColor: Colors.white,
);

static final lightTheme = ThemeData(
scaffoldBackgroundColor: Colors.white,
primaryColor: primaryColor,
colorScheme: ColorScheme.light(primary: primary),
dividerColor: Colors.black,
);
}
21 changes: 14 additions & 7 deletions basic_flutter/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
animated_theme_switcher:
dependency: "direct main"
description:
name: animated_theme_switcher
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
bloc:
dependency: "direct main"
description:
Expand All @@ -28,7 +35,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -122,7 +129,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -197,7 +204,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
typed_data:
dependency: transitive
description:
Expand All @@ -211,7 +218,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.16.0"
dart: ">=2.14.4 <3.0.0"
flutter: ">=2.5.3"
1 change: 1 addition & 0 deletions basic_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ environment:
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
animated_theme_switcher: ^2.0.6
bloc: ^7.2.1
cupertino_icons: ^1.0.2
flutter:
Expand Down