From 9def8daf0c876945550b5d5a33f9fb080774300f Mon Sep 17 00:00:00 2001 From: Janez T Date: Thu, 16 Oct 2025 14:57:11 +0200 Subject: [PATCH] feat: Refactor MaterialApp initialization into a separate method for improved readability --- lib/main.dart | 53 ++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1c3ea20..1c23f07 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -136,30 +136,35 @@ class _MeshCoreSarAppState extends State { ), ), ], - child: Builder( - builder: (context) { - final systemBrightness = MediaQuery.platformBrightnessOf(context); - return MaterialApp( - title: 'MeshCore SAR', - debugShowCheckedModeBanner: false, - theme: AppTheme.getTheme(_themeMode, systemBrightness), - locale: _locale, - localizationsDelegates: const [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: LocalePreferences.supportedLocales, - home: HomeScreen( - onThemeChanged: _handleThemeChanged, - onLocaleChanged: _handleLocaleChanged, - currentTheme: _themeMode, - currentLocale: _locale, - ), - ); - }, - ), + child: _buildMaterialApp(), + ); + } + + Widget _buildMaterialApp() { + return Builder( + builder: (context) { + final systemBrightness = MediaQuery.platformBrightnessOf(context); + return MaterialApp( + key: ValueKey('${_locale?.languageCode ?? 'system'}_${_themeMode.name}'), + title: 'MeshCore SAR', + debugShowCheckedModeBanner: false, + theme: AppTheme.getTheme(_themeMode, systemBrightness), + locale: _locale, + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: LocalePreferences.supportedLocales, + home: HomeScreen( + onThemeChanged: _handleThemeChanged, + onLocaleChanged: _handleLocaleChanged, + currentTheme: _themeMode, + currentLocale: _locale, + ), + ); + }, ); } }