Skip to content

Commit

Permalink
Update web build and adding framework for localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariemeth committed Nov 9, 2024
1 parent ef7a45b commit 7cc2116
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 58 deletions.
10 changes: 5 additions & 5 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "54e66469a933b60ddf175f858f82eaeb97e48c8d"
revision: "603104015dd692ea3403755b55d07813d5cf8965"
channel: "stable"

project_type: app
Expand All @@ -13,11 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
create_revision: 603104015dd692ea3403755b55d07813d5cf8965
base_revision: 603104015dd692ea3403755b55d07813d5cf8965
- platform: windows
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
create_revision: 603104015dd692ea3403755b55d07813d5cf8965
base_revision: 603104015dd692ea3403755b55d07813d5cf8965

# User provided section

Expand Down
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
#include: package:flutter_lints/flutter.yaml
# include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
Expand All @@ -24,6 +24,5 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
3 changes: 3 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/localization
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
15 changes: 15 additions & 0 deletions lib/localization/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@@locale": "en",
"appTitle": "Gearforce",
"@appTitle": {
"description": "The title of the application"
},
"menuTitle": "Menu",
"@menuTitle": {
"description": "The title name of the menu"
},
"menuSettingsTitle": "Settings",
"@menuSettingsTitle": {
"description": "The name of the settings menu button in the main menu"
}
}
24 changes: 22 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import 'package:gearforce/widgets/roster_id.dart';
import 'package:gearforce/widgets/settings.dart';
import 'package:gearforce/widgets/version_selector.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

const _title = 'Gearforce';
//const _title = 'Gearforce';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -18,7 +20,13 @@ Future<void> main() async {
final Settings settings = Settings();

final app = MaterialApp(
title: _title,
// Use AppLocalizations to configure the correct application title
// depending on the user's locale.
//
// The appTitle is defined in .arb files found in the localization
// directory.
onGenerateTitle: (BuildContext context) =>
AppLocalizations.of(context)!.appTitle,
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
Expand All @@ -27,6 +35,18 @@ Future<void> main() async {
primary: Colors.blue,
),
),
// Provide the generated AppLocalizations to the MaterialApp. This
// allows descendant Widgets to display the correct translations
// depending on the user's locale.
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''), // English, no country code
],
initialRoute: '/${VersionSelector.defaultSelectedVersion}',
routes: {
'/${VersionSelector.v3_1}': (context) => GearForceV3(
Expand Down
5 changes: 2 additions & 3 deletions lib/v3/gearforce_v3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:gearforce/widgets/roster_id.dart';
import 'package:gearforce/widgets/settings.dart';
import 'package:gearforce/widgets/version_selector.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class GearForceV3 extends StatefulWidget {
const GearForceV3({
Expand Down Expand Up @@ -48,14 +49,12 @@ class _GearForceV3State extends State<GearForceV3> {

@override
Widget build(BuildContext context) {
final title = 'Gearforce';

return MultiProvider(
providers: [
Provider<DataV3>(create: (_) => _v3Data),
],
child: RosterWidget(
title: title,
title: AppLocalizations.of(context)!.appTitle,
data: _v3Data,
rosterId: widget.rosterId,
version: widget.version,
Expand Down
5 changes: 3 additions & 2 deletions lib/v3/screens/roster/roster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:gearforce/widgets/settings.dart';
import 'package:gearforce/widgets/version_selector.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

const double _leftPanelWidth = 670.0;
const double _titleHeight = 40.0;
Expand Down Expand Up @@ -125,7 +126,7 @@ class _RosterWidgetState extends State<RosterWidget> {
decoration: BoxDecoration(color: Colors.blue),
child: Center(
child: Text(
'Menu',
AppLocalizations.of(context)!.menuTitle,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
Expand Down Expand Up @@ -343,7 +344,7 @@ class _RosterWidgetState extends State<RosterWidget> {
),
ListTile(
title: Text(
'Settings',
AppLocalizations.of(context)!.menuSettingsTitle,
style: TextStyle(
fontSize: 16,
),
Expand Down
17 changes: 2 additions & 15 deletions lib/v3/screens/settings/application_settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:gearforce/v3/screens/settings/settings_checkbox_option_line.dart
import 'package:gearforce/v3/screens/settings/settings_value_option_line.dart';
import 'package:gearforce/widgets/settings.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'settings_section_heading.dart';

Expand All @@ -23,7 +24,7 @@ class _ApplicationSettingsDialogState extends State<ApplicationSettingsDialog> {
title: Stack(children: [
Align(
child: Text(
'Settings',
AppLocalizations.of(context)!.menuSettingsTitle,
style: const TextStyle(fontSize: 24),
),
),
Expand Down Expand Up @@ -111,20 +112,6 @@ class _ApplicationSettingsDialogState extends State<ApplicationSettingsDialog> {
},
tooltipMessage: 'Allows adding a custom tv modifier upgrade to units',
),
// SettingsCheckboxOptionLine(
// // TODO: Enable when ready
// isEnabled: false,
// tooltipMessage: 'Coming soon!',
// text: 'Allow Extended Content',
// value: settings.isExtendedContentAllowed,
// onChanged: (bool? newValue) {
// setState(() {
// if (newValue != null) {
// settings.isExtendedContentAllowed = newValue;
// }
// });
// },
// ),
SimpleDialogOption(
onPressed: () {
Navigator.pop(context);
Expand Down
38 changes: 35 additions & 3 deletions lib/v4/gearforce_v4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'package:gearforce/widgets/roster_id.dart';
import 'package:gearforce/widgets/roster_title.dart';
import 'package:gearforce/widgets/settings.dart';
import 'package:gearforce/widgets/version_selector.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

const double _titleHeight = 40.0;
const double _menuTitleHeight = 50.0;

class GearForceV4 extends StatefulWidget {
const GearForceV4({
Expand Down Expand Up @@ -42,10 +44,8 @@ class _GearForceV4State extends State<GearForceV4> {

@override
Widget build(BuildContext context) {
final title = 'Gearforce';

final roster = RosterTitle(
title: title,
title: AppLocalizations.of(context)!.appTitle,
versionSelector: widget.versionSelector,
version: widget.version,
);
Expand All @@ -59,6 +59,38 @@ class _GearForceV4State extends State<GearForceV4> {
body: Center(
child: Text('Gearforce V4'),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Container(
height: _menuTitleHeight,
child: DrawerHeader(
child: Center(
child: Text(
AppLocalizations.of(context)!.menuTitle,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
color: Colors.white),
),
),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
),
),
ListTile(
title: Text(AppLocalizations.of(context)!.menuSettingsTitle),
onTap: () {
Navigator.pop(context);
// Navigator.pushNamed(context, '/settings');
},
),
],
),
),
);
}
}
29 changes: 29 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -293,6 +306,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.3.0"
intl:
dependency: transitive
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.19.0"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -333,6 +354,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
logging:
dependency: transitive
description:
Expand Down
8 changes: 7 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 1.16.2
version: 1.16.3
environment:
sdk: ">=3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand All @@ -42,6 +44,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
test: 1.25.7
flutter_lints: ^4.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand All @@ -53,6 +56,9 @@ flutter:
# the material Icons class.
uses-material-design: true

# Enable generation of localized Strings from arb files.
generate: true

# To add assets to your application, add an assets section, like this:
assets:
- assets/data/
Expand Down
30 changes: 6 additions & 24 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html>

<head>
<!--
If you are serving your web app in a path other than the root, change the
Expand Down Expand Up @@ -27,33 +28,14 @@
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<link rel="icon" type="image/png" href="favicon.png" />

<title>Gearforce</title>
<link rel="manifest" href="manifest.json">

<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>

<body>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
});
</script>
<script src="flutter_bootstrap.js" async></script>
</body>
</html>

</html>
2 changes: 1 addition & 1 deletion web/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"purpose": "maskable"
}
]
}
}

0 comments on commit 7cc2116

Please sign in to comment.