Skip to content

Commit 2a36d73

Browse files
dialog for thememode
1 parent ad63dd0 commit 2a36d73

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/widgets/theme_dialog.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
3+
import 'package:text_to_image_gen/utils/my_states.dart';
4+
5+
class ThemeModeDialog extends StatefulWidget {
6+
const ThemeModeDialog({Key? key}) : super(key: key);
7+
8+
@override
9+
_ThemeModeDialogState createState() => _ThemeModeDialogState();
10+
}
11+
12+
class _ThemeModeDialogState extends State<ThemeModeDialog> {
13+
final List<IconData> themeModeIcons = [
14+
Icons.light_mode,
15+
Icons.dark_mode,
16+
Icons.memory
17+
];
18+
19+
final List<String> themeModeText = ["Light", "Dark", "System"];
20+
21+
@override
22+
Widget build(BuildContext context) {
23+
final themeState = Provider.of<ThemeState>(context);
24+
return Dialog(
25+
child: ListView.builder(
26+
physics: const NeverScrollableScrollPhysics(),
27+
shrinkWrap: true,
28+
itemCount: 3,
29+
itemBuilder: (context, index) {
30+
return ListTileTheme(
31+
selectedColor: Theme.of(context).colorScheme.secondary,
32+
child: ListTile(
33+
leading: Icon(themeModeIcons[index]),
34+
title: Text(themeModeText[index]),
35+
selected: index == themeState.currentThemeIndex,
36+
onTap: () {
37+
themeState.changeThemeMode(index);
38+
Navigator.pop(context);
39+
},
40+
),
41+
);
42+
},
43+
),
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)