fix changing locale breaking everything yay

This commit is contained in:
zoe 2022-06-17 14:13:45 +02:00
parent e31246c892
commit 387d58dfa2
7 changed files with 53 additions and 25 deletions

View file

@ -1,7 +1 @@
import 'package:http/http.dart' as http;
import 'dart:io';
import 'package:oauth2/oauth2.dart' as oauth2;
// Future<http.Client> authorize({required String userid}) {
// }

9
lib/i18n/de_DE.json Normal file
View file

@ -0,0 +1,9 @@
{
"greeting": "hallo!",
"user-id-not-valid": "Hmm... die id sieht nicht ganz richtig aus...",
"user-id": "nutzer id",
"user-id-example": "nutzer@beispiel.de",
"authorize-in-browser": "im browser autorisieren",
"login-failed-snackbar-text": "login fehlgeschlagen!"
}

View file

@ -3,6 +3,7 @@
"user-id-not-valid": "Sorry, this user id doesn't look quite right... ", "user-id-not-valid": "Sorry, this user id doesn't look quite right... ",
"user-id": "user id", "user-id": "user id",
"user-id-example": "user@example.com", "user-id-example": "user@example.com",
"authorize-in-browser": "authorize in browser" "authorize-in-browser": "authorize in browser",
"login-failed-snackbar-text": "login failed!"
} }

View file

@ -2,12 +2,31 @@ import 'package:flutter/material.dart';
import 'package:localization/localization.dart'; import 'package:localization/localization.dart';
import 'package:slothmu/partials/main_scaffold.dart'; import 'package:slothmu/partials/main_scaffold.dart';
import 'pages/login.dart'; import 'pages/login.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(MaterialApp( void main() => runApp(const Slothmu());
class Slothmu extends StatefulWidget {
const Slothmu({Key? key}) : super(key: key);
@override
State<Slothmu> createState() => _SlothmuState();
}
class _SlothmuState extends State<Slothmu> {
@override
Widget build(BuildContext context) {
LocalJsonLocalization.delegate.directories = ['lib/i18n'];
return MaterialApp(
supportedLocales: const [ supportedLocales: const [
Locale("en", "US"), Locale("en", "US"),
Locale("de", "DE"),
], ],
locale: const Locale("de", "DE"),
localizationsDelegates: [ localizationsDelegates: [
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
LocalJsonLocalization.delegate, LocalJsonLocalization.delegate,
], ],
initialRoute: '/login', initialRoute: '/login',
@ -15,4 +34,6 @@ void main() => runApp(MaterialApp(
'/': (context) => const MainScaffold(), '/': (context) => const MainScaffold(),
'/login': (context) => const Login(), '/login': (context) => const Login(),
}, },
)); );
}
}

View file

@ -60,7 +60,11 @@ class _LoginFormState extends State<LoginForm> {
), ),
TextButton.icon( TextButton.icon(
onPressed: () { onPressed: () {
formKey.currentState!.validate(); bool isValid = formKey.currentState!.validate();
if (!isValid) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("login-failed-snackbar-text".i18n())));
}
}, },
icon: const Icon(Icons.login), icon: const Icon(Icons.login),
label: Text("authorize-in-browser".i18n())) label: Text("authorize-in-browser".i18n()))

View file

@ -43,13 +43,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.16.0" version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -76,6 +69,11 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -95,6 +93,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.1" version: "4.0.1"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.0"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -130,13 +135,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.7.0"
oauth2:
dependency: "direct main"
description:
name: oauth2
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
path: path:
dependency: transitive dependency: transitive
description: description:

View file

@ -29,6 +29,8 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_localizations: # Add this line
sdk: flutter
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
@ -36,7 +38,6 @@ dependencies:
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
settings_ui: ^2.0.2 settings_ui: ^2.0.2
http: ^0.13.4 http: ^0.13.4
oauth2: ^2.0.0
localization: ^2.1.0 localization: ^2.1.0
dev_dependencies: dev_dependencies: