From 4ce7efb5a5a74fea3d1e10fdf5d1c9c27bfa2969 Mon Sep 17 00:00:00 2001 From: whysman Date: Wed, 13 Nov 2024 23:11:47 -0500 Subject: [PATCH] adding menu with dialog and moving dialog text to l10n --- l10n.yaml | 3 ++ lib/custom_menu.dart | 98 ++++++++++++-------------------------------- lib/l10n/app_en.arb | 18 ++++++++ lib/main.dart | 10 +++++ pubspec.yaml | 10 ++++- 5 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 l10n.yaml create mode 100644 lib/l10n/app_en.arb diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 0000000..4e6692e --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,3 @@ +arb-dir: lib/l10n +template-arb-file: app_en.arb +output-localization-file: app_localizations.dart \ No newline at end of file diff --git a/lib/custom_menu.dart b/lib/custom_menu.dart index c473b14..192c8d6 100644 --- a/lib/custom_menu.dart +++ b/lib/custom_menu.dart @@ -1,6 +1,7 @@ // custom_menu_icon.dart import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class CustomMenu extends StatefulWidget { const CustomMenu({super.key}); @@ -23,29 +24,26 @@ class CustomMenuState extends State { // Detect taps outside the menu GestureDetector( onTap: _removeMenuOverlay, - behavior: - HitTestBehavior.translucent, // Ensures taps are detected + behavior: HitTestBehavior.translucent, child: Container( - color: Colors - .transparent, // Transparent background for full-screen detection + color: Colors.transparent, ), ), // Positioned menu overlay Positioned( - top: position.dy + 60, // Position below the icon + top: position.dy + 60, left: position.dx + 10, child: Material( color: Colors.transparent, child: Container( decoration: BoxDecoration( - color: Colors.white - .withOpacity(0.95), // Slightly transparent background + color: Colors.white.withOpacity(0.95), borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black26, blurRadius: 10, - offset: Offset(0, 4), // Shadow under the menu + offset: Offset(0, 4), ), ], ), @@ -85,7 +83,7 @@ class CustomMenuState extends State { return InkWell( onTap: () { _removeMenuOverlay(); - onTap(); // Open the specific dialog for this menu item + onTap(); }, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), @@ -114,85 +112,43 @@ class CustomMenuState extends State { ); } - // Dialog for "Home" option void _showHomeDialog() { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Home'), - content: Text('This is the Home dialog. Add your home content here.'), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text('Close'), - ), - ], - ); - }, - ); + _showDialog('Home', AppLocalizations.of(context)!.homeDialogContent); } - // Dialog for "Profile" option void _showProfileDialog() { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Profile'), - content: Text( - 'This is the Profile dialog. Add your profile content here.'), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text('Close'), - ), - ], - ); - }, - ); + _showDialog('Profile', AppLocalizations.of(context)!.profileDialogContent); } - // Dialog for "Settings" option void _showSettingsDialog() { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Settings'), - content: Text( - 'This is the Settings dialog. Add your settings content here.'), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text('Close'), - ), - ], - ); - }, - ); + _showDialog( + 'Settings', AppLocalizations.of(context)!.settingsDialogContent); } - // Dialog for "Logout" option void _showLogoutDialog() { + _showDialog('Logout', AppLocalizations.of(context)!.logoutDialogContent, + isLogout: true); + } + + void _showDialog(String title, String content, {bool isLogout = false}) { showDialog( context: context, builder: (context) { return AlertDialog( - title: Text('Logout'), - content: Text('Are you sure you want to log out?'), + title: Text(title), + content: Text(content), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), - child: Text('Cancel'), - ), - TextButton( - onPressed: () { - // Add your logout functionality here - Navigator.of(context).pop(); - }, - child: Text('Logout', style: TextStyle(color: Colors.red)), + child: Text(isLogout ? 'Cancel' : 'Close'), ), + if (isLogout) + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('Logout', style: TextStyle(color: Colors.red)), + ), ], ); }, @@ -206,7 +162,7 @@ class CustomMenuState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: Image.asset( - 'assets/logo.png', // Your custom icon path + 'assets/logo.png', height: 40, width: 40, ), diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb new file mode 100644 index 0000000..e882508 --- /dev/null +++ b/lib/l10n/app_en.arb @@ -0,0 +1,18 @@ +{ + "homeDialogContent": "This is the Home dialog. Add your home content here.", + "profileDialogContent": "This is the Profile dialog. Add your profile content here.", + "settingsDialogContent": "This is the Settings dialog. Add your settings content here.", + "logoutDialogContent": "Are you sure you want to log out?", + "@homeDialogContent": { + "description": "Text for the home dialog content." + }, + "@profileDialogContent": { + "description": "Text for the profile dialog content." + }, + "@settingsDialogContent": { + "description": "Text for the settings dialog content." + }, + "@logoutDialogContent": { + "description": "Text for the logout confirmation dialog content." + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index f89ffb7..5c95fc9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,11 +2,13 @@ import 'dart:async'; import 'dart:ui'; import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:provider/provider.dart'; import 'profile_screen.dart'; import 'shared_preferences_provider.dart'; import 'status_page.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; void main() { runApp( @@ -26,6 +28,14 @@ class MyApp extends StatelessWidget { title: 'Pogdark', theme: _buildTheme(), home: const HomeScreen(), + // Localization configuration + localizationsDelegates: [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: AppLocalizations.supportedLocales, ); } diff --git a/pubspec.yaml b/pubspec.yaml index c4c8a56..1930cb3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,12 +33,14 @@ dependencies: english_words: ^4.0.0 provider: ^6.1.2 web_socket_channel: ^3.0.1 - shared_preferences: ^2.0.9 + shared_preferences: ^2.3.3 image_picker: ^1.1.2 uuid: ^4.4.2 fluttertoast: ^8.2.8 http: ^1.2.2 - flutter_dotenv: ^5.0.3 + intl: ^0.19.0 + flutter_localizations: + sdk: flutter # The following adds the Cupertino Icons font to your application. @@ -71,10 +73,14 @@ flutter: # the material Icons class. uses-material-design: true + #localization + generate: true + # To add assets to your application, add an assets section, like this: assets: - assets/default_profile_image.png - assets/pogdark_logo.png + - assets/logo.png # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg