adding menu with dialog and moving dialog text to l10n
All checks were successful
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Successful in 3m12s

This commit is contained in:
whysman 2024-11-13 23:11:47 -05:00
parent 43467e0a72
commit 4ce7efb5a5
5 changed files with 66 additions and 73 deletions

3
l10n.yaml Normal file
View File

@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

View File

@ -1,6 +1,7 @@
// custom_menu_icon.dart // custom_menu_icon.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class CustomMenu extends StatefulWidget { class CustomMenu extends StatefulWidget {
const CustomMenu({super.key}); const CustomMenu({super.key});
@ -23,29 +24,26 @@ class CustomMenuState extends State<CustomMenu> {
// Detect taps outside the menu // Detect taps outside the menu
GestureDetector( GestureDetector(
onTap: _removeMenuOverlay, onTap: _removeMenuOverlay,
behavior: behavior: HitTestBehavior.translucent,
HitTestBehavior.translucent, // Ensures taps are detected
child: Container( child: Container(
color: Colors color: Colors.transparent,
.transparent, // Transparent background for full-screen detection
), ),
), ),
// Positioned menu overlay // Positioned menu overlay
Positioned( Positioned(
top: position.dy + 60, // Position below the icon top: position.dy + 60,
left: position.dx + 10, left: position.dx + 10,
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white color: Colors.white.withOpacity(0.95),
.withOpacity(0.95), // Slightly transparent background
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black26, color: Colors.black26,
blurRadius: 10, blurRadius: 10,
offset: Offset(0, 4), // Shadow under the menu offset: Offset(0, 4),
), ),
], ],
), ),
@ -85,7 +83,7 @@ class CustomMenuState extends State<CustomMenu> {
return InkWell( return InkWell(
onTap: () { onTap: () {
_removeMenuOverlay(); _removeMenuOverlay();
onTap(); // Open the specific dialog for this menu item onTap();
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
@ -114,85 +112,43 @@ class CustomMenuState extends State<CustomMenu> {
); );
} }
// Dialog for "Home" option
void _showHomeDialog() { void _showHomeDialog() {
showDialog( _showDialog('Home', AppLocalizations.of(context)!.homeDialogContent);
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'),
),
],
);
},
);
} }
// Dialog for "Profile" option
void _showProfileDialog() { void _showProfileDialog() {
showDialog( _showDialog('Profile', AppLocalizations.of(context)!.profileDialogContent);
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'),
),
],
);
},
);
} }
// Dialog for "Settings" option
void _showSettingsDialog() { void _showSettingsDialog() {
showDialog( _showDialog(
context: context, 'Settings', AppLocalizations.of(context)!.settingsDialogContent);
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'),
),
],
);
},
);
} }
// Dialog for "Logout" option
void _showLogoutDialog() { void _showLogoutDialog() {
_showDialog('Logout', AppLocalizations.of(context)!.logoutDialogContent,
isLogout: true);
}
void _showDialog(String title, String content, {bool isLogout = false}) {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return AlertDialog(
title: Text('Logout'), title: Text(title),
content: Text('Are you sure you want to log out?'), content: Text(content),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'), child: Text(isLogout ? 'Cancel' : 'Close'),
),
TextButton(
onPressed: () {
// Add your logout functionality here
Navigator.of(context).pop();
},
child: Text('Logout', style: TextStyle(color: Colors.red)),
), ),
if (isLogout)
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Logout', style: TextStyle(color: Colors.red)),
),
], ],
); );
}, },
@ -206,7 +162,7 @@ class CustomMenuState extends State<CustomMenu> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset( child: Image.asset(
'assets/logo.png', // Your custom icon path 'assets/logo.png',
height: 40, height: 40,
width: 40, width: 40,
), ),

18
lib/l10n/app_en.arb Normal file
View File

@ -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."
}
}

View File

@ -2,11 +2,13 @@ import 'dart:async';
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'profile_screen.dart'; import 'profile_screen.dart';
import 'shared_preferences_provider.dart'; import 'shared_preferences_provider.dart';
import 'status_page.dart'; import 'status_page.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
void main() { void main() {
runApp( runApp(
@ -26,6 +28,14 @@ class MyApp extends StatelessWidget {
title: 'Pogdark', title: 'Pogdark',
theme: _buildTheme(), theme: _buildTheme(),
home: const HomeScreen(), home: const HomeScreen(),
// Localization configuration
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
); );
} }

View File

@ -33,12 +33,14 @@ dependencies:
english_words: ^4.0.0 english_words: ^4.0.0
provider: ^6.1.2 provider: ^6.1.2
web_socket_channel: ^3.0.1 web_socket_channel: ^3.0.1
shared_preferences: ^2.0.9 shared_preferences: ^2.3.3
image_picker: ^1.1.2 image_picker: ^1.1.2
uuid: ^4.4.2 uuid: ^4.4.2
fluttertoast: ^8.2.8 fluttertoast: ^8.2.8
http: ^1.2.2 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. # The following adds the Cupertino Icons font to your application.
@ -71,10 +73,14 @@ flutter:
# the material Icons class. # the material Icons class.
uses-material-design: true uses-material-design: true
#localization
generate: true
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
assets: assets:
- assets/default_profile_image.png - assets/default_profile_image.png
- assets/pogdark_logo.png - assets/pogdark_logo.png
- assets/logo.png
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg