mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Automatically apply new dark theme settings
This commit is contained in:
		@@ -28,7 +28,7 @@ void subMain() async {
 | 
			
		||||
  ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ComunicApplication extends StatelessWidget {
 | 
			
		||||
class ComunicApplication extends StatefulWidget {
 | 
			
		||||
  final PreferencesHelper preferences;
 | 
			
		||||
 | 
			
		||||
  const ComunicApplication({
 | 
			
		||||
@@ -37,12 +37,22 @@ class ComunicApplication extends StatelessWidget {
 | 
			
		||||
  })  : assert(preferences != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  ComunicApplicationState createState() => ComunicApplicationState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ComunicApplicationState extends State<ComunicApplication> {
 | 
			
		||||
  /// Use this method to force the application to rebuild
 | 
			
		||||
  void refresh() => setState(() {});
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return MaterialApp(
 | 
			
		||||
      debugShowCheckedModeBanner: false,
 | 
			
		||||
      home: AccountHelper.isUserIDLoaded ? InitializeWidget() : LoginRoute(),
 | 
			
		||||
      theme: preferences.preferences.enableDarkMode ? ThemeData.dark() : null,
 | 
			
		||||
      theme: widget.preferences.preferences.enableDarkMode
 | 
			
		||||
          ? ThemeData.dark()
 | 
			
		||||
          : null,
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -74,6 +74,7 @@ class __ApplicationSettingsScreenState
 | 
			
		||||
  /// Apply new settings
 | 
			
		||||
  _updatedSettings() {
 | 
			
		||||
    setState(() {});
 | 
			
		||||
    applyNewThemeSettings(context);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:comunic/helpers/preferences_helper.dart';
 | 
			
		||||
import 'package:comunic/main.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/full_screen_image.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/dialogs/auto_sized_dialog_content_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
@@ -222,3 +223,7 @@ void showAboutAppDialog(BuildContext context) {
 | 
			
		||||
        ),
 | 
			
		||||
      ]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Apply new theme settings
 | 
			
		||||
void applyNewThemeSettings(BuildContext context) =>
 | 
			
		||||
    context.findAncestorStateOfType<ComunicApplicationState>().refresh();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user