From 216a5971b2d2551901db85bc6680455e34af2b70 Mon Sep 17 00:00:00 2001 From: vjrj <vjrj@comunes.org> Date: Wed, 12 Apr 2023 19:01:32 +0200 Subject: [PATCH] Added theme switch. Link to weblate --- assets/translations/en.json | 3 ++- assets/translations/es.json | 3 ++- lib/main.dart | 4 ++++ lib/ui/screens/fifth_screen.dart | 26 +++++++++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 89f85cee..170227ef 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -137,5 +137,6 @@ "notification_new_sent_desc": "You have sent a {amount} to {to}", "contact_already_exists": "Contact already exists", "wrong_public_key": "Wrong public key", - "browser_warning": "You are using a browser we didn't test. Please use Chrome, Firefox or Brave." + "browser_warning": "You are using a browser we didn't test. Please use Chrome, Firefox or Brave.", + "code_translate": "Help us to translate Ğ1nkgo" } diff --git a/assets/translations/es.json b/assets/translations/es.json index 7f2ca419..204e955b 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -137,5 +137,6 @@ "notification_new_sent_desc": "Has enviado un nuevo pago de {amount} a {to}", "contact_already_exists": "Contacto ya existente", "wrong_public_key": "Clave pública incorrecta", - "browser_warning": "Estas usando un navegador que no hemos testeado. Por favor, usa Chrome, Firefox o Brave." + "browser_warning": "Estas usando un navegador que no hemos testeado. Por favor, usa Chrome, Firefox o Brave.", + "code_translate": "Ayúdanos a traducir Ğ1nkgo" } diff --git a/lib/main.dart b/lib/main.dart index 47f7178e..e6817ed9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,6 +23,7 @@ import 'package:sentry_logging/sentry_logging.dart'; import 'app_bloc_observer.dart'; import 'config/theme.dart'; import 'cubit/bottom_nav_cubit.dart'; +import 'cubit/theme_cubit.dart'; import 'data/models/app_cubit.dart'; import 'data/models/app_state.dart'; import 'data/models/contact_cubit.dart'; @@ -113,6 +114,8 @@ void main() async { create: (BuildContext context) => ContactsCubit()), BlocProvider<TransactionsCubit>( create: (BuildContext context) => TransactionsCubit()), + BlocProvider<ThemeCubit>( + create: (BuildContext context) => ThemeCubit()), // Add other BlocProviders here if needed ], child: const GinkgoApp()), ), @@ -326,6 +329,7 @@ class _GinkgoAppState extends State<GinkgoApp> { navigatorKey: GinkgoApp.navigatorKey, /// Theme stuff + themeMode: context.watch<ThemeCubit>().state.themeMode, /// Localization stuff localizationsDelegates: context.localizationDelegates, diff --git a/lib/ui/screens/fifth_screen.dart b/lib/ui/screens/fifth_screen.dart index 3fa18fc5..fd60dc61 100644 --- a/lib/ui/screens/fifth_screen.dart +++ b/lib/ui/screens/fifth_screen.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:pwa_install/pwa_install.dart'; import 'package:share_plus/share_plus.dart'; +import '../../cubit/theme_cubit.dart'; import '../../data/models/app_cubit.dart'; import '../../data/models/app_state.dart'; import '../../data/models/node_type.dart'; @@ -27,7 +28,24 @@ class FifthScreen extends StatelessWidget { Widget build(BuildContext context) { return BlocBuilder<AppCubit, AppState>( builder: (BuildContext context, AppState state) => Scaffold( - appBar: AppBar(title: Text(tr('bottom_nav_fifth'))), + appBar: AppBar( + title: Text(tr('bottom_nav_fifth')), + actions: <Widget>[ + IconButton( + icon: Icon(context.watch<ThemeCubit>().isDark() + ? Icons.wb_sunny + : Icons.nights_stay), + onPressed: () { + BlocProvider.of<ThemeCubit>(context).getTheme( + ThemeModeState( + themeMode: context.read<ThemeCubit>().isDark() + ? ThemeMode.light + : ThemeMode.dark)); + }, + ), + const SizedBox(width: 10), + ], + ), drawer: const CardDrawer(), body: ListView( padding: const EdgeInsets.symmetric(horizontal: 16), @@ -163,6 +181,12 @@ class FifthScreen extends StatelessWidget { icon: Icons.code_rounded, url: Uri.parse('https://git.duniter.org/vjrj/ginkgo')), + if (state.expertMode) + LinkCard( + title: 'code_translate', + icon: Icons.translate, + url: Uri.parse( + 'https://weblate.duniter.org/projects/g1nkgo/g1nkgo/')), const BottomWidget(), SwitchListTile( title: Text(tr('expert_mode')), -- GitLab