getx icon indicating copy to clipboard operation
getx copied to clipboard

get 4.6.5.. Get.isDarkMode is always giving false value.

Open hayatbangash55 opened this issue 2 years ago • 1 comments

This code is working fine... Get.changeThemeMode(value ? ThemeMode.dark : ThemeMode.light);

but it is not updating the ThemeMode value therefore i am always getting false from Get.isDarkMode please correct this issue...

e.g
color: Get.isDarkMode ? ColorHelper.darkTertiary : ColorHelper.lightPrimary,

hayatbangash55 avatar Jun 22 '22 10:06 hayatbangash55

I have same issue

tiennguyen9988 avatar Jun 26 '22 03:06 tiennguyen9988

any updated ?

hanhmh1203 avatar Aug 19 '22 05:08 hanhmh1203

I think, func changetheme/changethememode, sometime can not change the theme

hanhmh1203 avatar Aug 19 '22 05:08 hanhmh1203

Use Theme.of(context)

KyawSoeW1n avatar Sep 11 '22 10:09 KyawSoeW1n

You have to use context with function isDarkMode because it is not working with Get keyword.

Like: context.isDarkMode

as i have found the solution so i am closing this issue.

hayatbangash55 avatar Sep 12 '22 05:09 hayatbangash55

import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart';

class ThemeService { final _box = GetStorage(); final _key = 'isDarkMode';

/// Get isDarkMode info from local storage and return ThemeMode ThemeMode get theme => loadThemeFromBox() ? ThemeMode.dark : ThemeMode.light;

/// Load isDArkMode from local storage and if it's empty, returns false (that means default theme is light) bool loadThemeFromBox() => _box.read(_key) ?? false;

/// Save isDarkMode to local storage _saveThemeToBox(bool isDarkMode) => _box.write(_key, isDarkMode);

/// Switch theme and save to local storage void switchTheme() { Get.changeThemeMode(loadThemeFromBox() ? ThemeMode.light : ThemeMode.dark); _saveThemeToBox(!loadThemeFromBox()); } }

use when ThemeService().loadThemeFromBox() to replace with Get.isDarkMode. its works fine.

SamarthSerpentCS avatar May 17 '23 06:05 SamarthSerpentCS

you need to configure theme and darkTheme of GetMaterialApp. Open the lib/main.dart file and modify it like the below.

import 'package:get/get.dart';

class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);

@override Widget build(BuildContext context) { return GetMaterialApp( title: 'Flutter Demo', home: const MyHomePage(), ); } }

batoolhh avatar May 20 '23 09:05 batoolhh

i'm trying to use Get.isDarkMode, context.isDarkMode, Get.context!.isDarkMode and SchedulerBinding.instance.platformDispatcher.platformBrightness but nothing works, some solution?

gabriieelreeis avatar Jan 04 '24 12:01 gabriieelreeis

i'm trying to use Get.isDarkMode, context.isDarkMode, Get.context!.isDarkMode and SchedulerBinding.instance.platformDispatcher.platformBrightness but nothing works, some solution?

Are u using? Get.changeThemeMode(value ? ThemeMode.dark : ThemeMode.light);

hayatbangash55 avatar Jan 08 '24 11:01 hayatbangash55

i'm trying to use Get.isDarkMode, context.isDarkMode, Get.context!.isDarkMode and SchedulerBinding.instance.platformDispatcher.platformBrightness but nothing works, some solution?

Are u using? Get.changeThemeMode(value ? ThemeMode.dark : ThemeMode.light);

Yes Sr, my solution was to use a controller with the current theme value and also using local storage to store the current theme in memory.

gabriieelreeis avatar Jan 08 '24 13:01 gabriieelreeis

Use Theme.of(context)

Worked for me

niamulhasan avatar Jan 10 '24 16:01 niamulhasan

One thing to remember: Create Theme classes like this : static final dark = ThemeData.dark().copyWith( static final light = ThemeData.light().copyWith(

after doing like this u will get the right value from context.isDarkMode

hayatbangash55 avatar Jan 11 '24 06:01 hayatbangash55