Skip to content

Commit

Permalink
fixed theme bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mastermind-sap committed Jun 17, 2024
1 parent a087b11 commit 42e4091
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 26 deletions.
Binary file added .gradle/8.0.2/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.0.2/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/8.0.2/fileHashes/fileHashes.lock
Binary file not shown.
Empty file added .gradle/8.0.2/gc.properties
Empty file.
26 changes: 3 additions & 23 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ class _HomePageState extends State<HomePage> {
void initState() {
// showNotification();
super.initState();
_getInitialThemeMode();
}

int _initialLabelIndex = 0;
void _getInitialThemeMode() async {
final savedThemeMode = await AdaptiveTheme.getThemeMode();
setState(() {
if (savedThemeMode == AdaptiveThemeMode.light) {
_initialLabelIndex = 0;
} else if (savedThemeMode == AdaptiveThemeMode.dark) {
_initialLabelIndex = 1;
} else {
_initialLabelIndex = 0;
}
});
}

//show various notification from here
Expand Down Expand Up @@ -191,20 +176,15 @@ class _HomePageState extends State<HomePage> {
onTap: () {},
child: ListTile(
leading: Icon(
_initialLabelIndex == 0
AdaptiveTheme.of(context).mode.isDark
? FontAwesomeIcons.solidSun
: FontAwesomeIcons.solidMoon,
),
title: const Text('Switch Theme'),
onTap: () {
setState(() {
if (_initialLabelIndex == 0) {
_initialLabelIndex = 1;
AdaptiveTheme.of(context).setDark();
} else {
_initialLabelIndex = 0;
AdaptiveTheme.of(context).setLight();
}
AdaptiveTheme.of(context)
.toggleThemeMode(useSystem: false);
});
},
),
Expand Down
8 changes: 5 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import 'splash_screen.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
final savedThemeMode = await AdaptiveTheme.getThemeMode();
await NotificationService.initialNotification();
runApp(const OpSoApp());
runApp(OpSoApp(savedThemeMode: savedThemeMode));
}

class OpSoApp extends StatelessWidget {
const OpSoApp({super.key});
final AdaptiveThemeMode? savedThemeMode;
const OpSoApp({super.key, this.savedThemeMode});

@override
Widget build(BuildContext context) {
Expand All @@ -33,7 +35,7 @@ class OpSoApp extends StatelessWidget {
return AdaptiveTheme(
light: ThemeData.light(),
dark: ThemeData.dark(),
initial: AdaptiveThemeMode.system,
initial: savedThemeMode ?? AdaptiveThemeMode.light,
builder: (theme, darkTheme) => MaterialApp(
initialRoute: '/splash_screen',
routes: {
Expand Down

0 comments on commit 42e4091

Please sign in to comment.