mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can toggle dark mode from menu on tablet mode
This commit is contained in:
		@@ -76,6 +76,12 @@ class PreferencesHelper {
 | 
			
		||||
  ApplicationPreferences get preferences => ApplicationPreferences(
 | 
			
		||||
        enableDarkMode: getBool(PreferencesKeyList.ENABLE_DARK_THEME),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  /// Apply new preferences
 | 
			
		||||
  Future<void> setPreferences(ApplicationPreferences preferences) async {
 | 
			
		||||
    await setBool(
 | 
			
		||||
        PreferencesKeyList.ENABLE_DARK_THEME, preferences.enableDarkMode);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PreferencesHelper preferences() {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@ import 'package:flutter/cupertino.dart';
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class ApplicationPreferences {
 | 
			
		||||
  final bool enableDarkMode;
 | 
			
		||||
  bool enableDarkMode;
 | 
			
		||||
 | 
			
		||||
  const ApplicationPreferences({
 | 
			
		||||
  ApplicationPreferences({
 | 
			
		||||
    @required this.enableDarkMode,
 | 
			
		||||
  }) : assert(enableDarkMode != null);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import 'package:comunic/helpers/events_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/notifications_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/preferences_helper.dart';
 | 
			
		||||
import 'package:comunic/models/count_unread_notifications.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/notifications_screen.dart';
 | 
			
		||||
@@ -7,6 +8,7 @@ import 'package:comunic/ui/screens/unread_conversations_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/tablet_mode/appbar_custom_dropdown_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Comunic tablet AppBar widget
 | 
			
		||||
@@ -84,6 +86,14 @@ class _ComunicTabletAppBarWidgetState
 | 
			
		||||
        PopupMenuButton<_MenuItemCallback>(
 | 
			
		||||
          offset: Offset(0, 50),
 | 
			
		||||
          itemBuilder: (c) => [
 | 
			
		||||
            // Toggle dark theme
 | 
			
		||||
            _MainMenuItem(
 | 
			
		||||
                label: tr("Night mode"),
 | 
			
		||||
                icon: preferences().preferences.enableDarkMode
 | 
			
		||||
                    ? Icons.brightness_2
 | 
			
		||||
                    : Icons.wb_sunny,
 | 
			
		||||
                onTap: _toggleDarkMode),
 | 
			
		||||
 | 
			
		||||
            // Sign out
 | 
			
		||||
            _MainMenuItem(
 | 
			
		||||
                label: tr("Sign out"),
 | 
			
		||||
@@ -95,6 +105,15 @@ class _ComunicTabletAppBarWidgetState
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Toggle dark mode
 | 
			
		||||
  void _toggleDarkMode() async {
 | 
			
		||||
    final prefs = preferences().preferences;
 | 
			
		||||
    prefs.enableDarkMode = !prefs.enableDarkMode;
 | 
			
		||||
    await preferences().setPreferences(prefs);
 | 
			
		||||
 | 
			
		||||
    applyNewThemeSettings(context);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef _MenuItemCallback = void Function();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user