mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 08:24:05 +02:00
fix dimmed safearea and translate error messages
This commit is contained in:
parent
0b2b6f5a18
commit
57133e7a13
@ -19,6 +19,9 @@ import 'package:mobile/controllers/routing.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
ErrorMessages.init("danish");
|
||||
|
||||
final server = BackendServer();
|
||||
final usersController = UsersController(server: server);
|
||||
final sessionController = SessionController(server: server);
|
||||
|
@ -3,6 +3,7 @@ import 'package:mobile/controllers/routing.dart';
|
||||
import 'package:mobile/controllers/cart.dart';
|
||||
import 'package:mobile/controllers/paying_state.dart';
|
||||
import 'package:mobile/results.dart';
|
||||
import 'package:mobile/server/server.dart';
|
||||
import 'package:mobile/utils/price.dart';
|
||||
import 'package:mobile/widgets/primary_button.dart';
|
||||
import 'package:mobile/widgets/receipt_item.dart';
|
||||
@ -20,10 +21,10 @@ class FinishShoppingPage extends StatelessWidget {
|
||||
final cart = cartController.allCartItems();
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
body: Stack(
|
||||
children: [
|
||||
SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const BackButton(),
|
||||
@ -57,14 +58,13 @@ class FinishShoppingPage extends StatelessWidget {
|
||||
payingStateRepo.next();
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (await cartController.purchase()
|
||||
is Err<Null, String>) {
|
||||
case Err<Null, String>(value: final message)) {
|
||||
if (context.mounted) {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) =>
|
||||
AlertDialog(
|
||||
content: const Text(
|
||||
'Du har desværre ikke råd til at købe dette'),
|
||||
content: Text(ErrorMessages.fancy(message)),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
@ -93,55 +93,55 @@ class FinishShoppingPage extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (payingStateRepo.state != PayingState.unset) ...[
|
||||
Container(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
),
|
||||
],
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
...switch (payingStateRepo.state) {
|
||||
PayingState.unset => [],
|
||||
PayingState.loading => [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
color: Colors.white,
|
||||
),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context).primaryColor),
|
||||
strokeWidth: 6.0,
|
||||
),
|
||||
),
|
||||
if (payingStateRepo.state != PayingState.unset) ...[
|
||||
Container(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
),
|
||||
],
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
...switch (payingStateRepo.state) {
|
||||
PayingState.unset => [],
|
||||
PayingState.loading => [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
color: Colors.white,
|
||||
),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context).primaryColor),
|
||||
strokeWidth: 6.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
PayingState.done => [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
size: 70,
|
||||
),
|
||||
)
|
||||
]
|
||||
},
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
PayingState.done => [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
size: 70,
|
||||
),
|
||||
)
|
||||
]
|
||||
},
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile/models/cart_item.dart';
|
||||
import 'package:mobile/models/product.dart';
|
||||
@ -32,3 +33,62 @@ abstract class Server {
|
||||
|
||||
Image productImage(int productId);
|
||||
}
|
||||
|
||||
class ErrorMessages {
|
||||
final String language;
|
||||
|
||||
static ErrorMessages? _instance;
|
||||
|
||||
static init(String language) {
|
||||
_instance = ErrorMessages(language: language);
|
||||
}
|
||||
|
||||
static ErrorMessages get instance {
|
||||
final instance = _instance;
|
||||
if (instance == null) {
|
||||
throw NotInitialized();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
ErrorMessages({required this.language});
|
||||
|
||||
static String fancy(String message) {
|
||||
return instance._fancy(message);
|
||||
}
|
||||
|
||||
String _fancy(String message) {
|
||||
switch (language) {
|
||||
case "danish":
|
||||
return _fancyDanish(message);
|
||||
default:
|
||||
return "error: $message";
|
||||
}
|
||||
}
|
||||
|
||||
String _fancyDanish(String message) {
|
||||
switch (message) {
|
||||
case "insufficient funds":
|
||||
return "Du har desværre ikke nok penge på kontoen.";
|
||||
|
||||
default:
|
||||
if (kDebugMode) {
|
||||
throw NotTranslated(message: message);
|
||||
}
|
||||
return "error: $message";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotInitialized implements Exception {}
|
||||
|
||||
class NotTranslated implements Exception {
|
||||
final String message;
|
||||
|
||||
NotTranslated({required this.message});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${super.toString()}: message \"$message\" is not translated";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user