-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path45.flutter_checkbox_dark_theme.dart
55 lines (49 loc) · 1.9 KB
/
45.flutter_checkbox_dark_theme.dart
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
import 'package:flutter/material.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
import 'package:provider/provider.dart';
class CheckboxNotifier extends ChangeNotifier {
bool isChecked = true;
void toggleCheckmark() {
isChecked = !isChecked;
notifyListeners();
}
}
class FlutterCheckboxDemoView extends StatelessWidget {
const FlutterCheckboxDemoView({super.key});
@override
Widget build(BuildContext context) {
CheckboxNotifier checkboxNotifier({required bool renderUI}) =>
Provider.of<CheckboxNotifier>(context, listen: renderUI);
bool isDark = checkboxNotifier(renderUI: true).isChecked;
return Scaffold(
backgroundColor:
isDark ? KConstantColors.whiteColor : KConstantColors.bgColorFaint,
appBar: CustomAppBar(title: "Flutter Checkbox"),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ListTile(
title: Text("Dark theme 🧛🏻♀️",
style: KConstantTextstyles.bold(
fontSize: 14,
color: isDark
? KConstantColors.bgColor
: KConstantColors.whiteColor)),
subtitle: Text("Changes theme of app to dark version",
style: KConstantTextstyles.light(
fontSize: 12,
color: isDark
? KConstantColors.bgColor
: KConstantColors.whiteColor)),
leading: Checkbox(
value: !checkboxNotifier(renderUI: true).isChecked,
onChanged: (val) {
checkboxNotifier(renderUI: false).toggleCheckmark();
}),
)
],
));
}
}