Clean code + add language logic (not supported)
This commit is contained in:
parent
636c64297b
commit
f8ef485428
@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mymuseum_visitapp/Components/LanguageSelection.dart';
|
||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||
import 'package:mymuseum_visitapp/Screens/Home/home.dart';
|
||||
import 'package:mymuseum_visitapp/constants.dart';
|
||||
//import 'package:flutter_svg/svg.dart';
|
||||
import 'package:mymuseum_visitapp/app_context.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
@ -20,12 +20,11 @@ class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
}
|
||||
|
||||
class _CustomAppBarState extends State<CustomAppBar> {
|
||||
final double _preferredHeight = 50;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
//final index = Provider.of<Index>(context);
|
||||
final appContext = Provider.of<AppContext>(context);
|
||||
|
||||
final notchInset = MediaQuery.of(context).padding;
|
||||
return AppBar(
|
||||
title: Text(widget.title),
|
||||
@ -35,15 +34,17 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
onPressed: () {
|
||||
// Set new State
|
||||
setState(() {
|
||||
VisitAppContext visitAppContext = appContext.getContext();
|
||||
visitAppContext.configuration = null;
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||
builder: (context) => const HomePage(),
|
||||
));
|
||||
});
|
||||
}
|
||||
) : null,
|
||||
actions: [
|
||||
actions: const [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 10.0),
|
||||
padding: EdgeInsets.only(right: 10.0),
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
|
||||
@ -4,8 +4,6 @@ import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||
import 'package:mymuseum_visitapp/app_context.dart';
|
||||
import 'package:mymuseum_visitapp/constants.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
||||
import '../Helpers/DatabaseHelper.dart';
|
||||
|
||||
class LanguageSelection extends StatefulWidget {
|
||||
@ -26,16 +24,15 @@ class _LanguageSelection extends State<LanguageSelection> with TickerProviderSta
|
||||
Widget build(BuildContext context) {
|
||||
final appContext = Provider.of<AppContext>(context);
|
||||
Size size = MediaQuery.of(context).size;
|
||||
var configurationLanguages = (appContext.getContext() as VisitAppContext).configuration?.languages;
|
||||
VisitAppContext visitAppContext = appContext.getContext();
|
||||
var configurationLanguages = visitAppContext.configuration?.languages;
|
||||
//print(configurationLanguages);
|
||||
languagesEnable = configurationLanguages ?? languages;
|
||||
selectedLanguage = (appContext.getContext() as VisitAppContext).language;
|
||||
selectedLanguage = visitAppContext.language;
|
||||
|
||||
if(!languagesEnable!.any((lg) => lg == selectedLanguage)) {
|
||||
//print("selectedLanguage not supported");
|
||||
selectedLanguage = defaultLanguage;
|
||||
}
|
||||
//print(selectedLanguage);
|
||||
|
||||
return PopupMenuButton(
|
||||
icon: Container(
|
||||
|
||||
@ -130,9 +130,9 @@ class _ScannerDialogState extends State<ScannerDialog> {
|
||||
this.controller = controller;
|
||||
});
|
||||
if (Platform.isAndroid) {
|
||||
controller!.pauseCamera();
|
||||
controller.pauseCamera();
|
||||
}
|
||||
controller!.resumeCamera();
|
||||
controller.resumeCamera();
|
||||
controller.scannedDataStream.listen((scanData) {
|
||||
setState(() {
|
||||
result = scanData;
|
||||
@ -146,7 +146,7 @@ class _ScannerDialogState extends State<ScannerDialog> {
|
||||
|
||||
VisitAppContext visitAppContext = widget.appContext!.getContext();
|
||||
|
||||
if(!visitAppContext!.sectionIds!.contains(code)) {
|
||||
if(!visitAppContext.sectionIds!.contains(code)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(TranslationHelper.getFromLocale('invalidQRCode', widget.appContext!)), backgroundColor: kBlue2),
|
||||
);
|
||||
|
||||
@ -5,6 +5,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:manager_api/api.dart';
|
||||
import 'package:mymuseum_visitapp/Components/ConfirmationDialog.dart';
|
||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
||||
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
||||
@ -64,8 +65,14 @@ class _HomePageState extends State<HomePage> {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
if(configurations[index].isOffline! && alreadyDownloaded.any((c) => c == configurations[index].id)) {
|
||||
// Update context
|
||||
VisitAppContext visitAppContext = appContext.getContext();
|
||||
|
||||
if(!configurations[index].languages!.contains(visitAppContext.language)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(TranslationHelper.getFromLocale("languageNotSupported", appContext)), backgroundColor: kBlue2),
|
||||
);
|
||||
} else {
|
||||
// Update context
|
||||
visitAppContext.configuration = configurations[index];
|
||||
visitAppContext.sectionIds = List<SectionDTO>.from(await DatabaseHelper.instance.queryWithConfigurationId(DatabaseTableType.sections, visitAppContext.configuration!.id!)).map((e) => e.id).toList();
|
||||
appContext.setContext(visitAppContext);
|
||||
@ -73,6 +80,7 @@ class _HomePageState extends State<HomePage> {
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||
builder: (context) => VisitPage(configurationId: configurations[index].id!),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(TranslationHelper.getFromLocale("visitDownloadWarning", appContext)), backgroundColor: kBlue2),
|
||||
@ -138,9 +146,9 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
floatingActionButton: ScannerBouton(isReplacement: false, appContext: appContext!),
|
||||
floatingActionButton: ScannerBouton(isReplacement: false, appContext: appContext),
|
||||
//floatingActionButtonLocation: FloatingActionButtonLocation.miniCenterFloat,
|
||||
);
|
||||
}
|
||||
@ -154,10 +162,10 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
if(isOnline) {
|
||||
configurations = await client.configurationApi!.configurationGet();
|
||||
return configurations ?? [];
|
||||
} else {
|
||||
return configurations ?? [];
|
||||
}
|
||||
|
||||
return configurations;
|
||||
|
||||
} catch (e) {
|
||||
print(e);
|
||||
print("IN CATCH");
|
||||
@ -242,7 +250,7 @@ class _HomePageState extends State<HomePage> {
|
||||
ArticleDTO? articleDTO = ArticleDTO.fromJson(jsonDecode(section.data!));
|
||||
|
||||
if(articleDTO != null) {
|
||||
for(var image in articleDTO!.images!) {
|
||||
for(var image in articleDTO.images!) {
|
||||
await getAndDownloadImage(appContext.clientAPI, image);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,10 +128,10 @@ class _BodyState extends State<Body> {
|
||||
sectionsToDisplay = sections;
|
||||
|
||||
if(searchValue != '' && searchValue != null) {
|
||||
sectionsToDisplay = sections.where((s) => TranslationHelper.get(s!.title, appContext).toLowerCase().contains(searchValue.toString().toLowerCase())).toList();
|
||||
sectionsToDisplay = sections.where((s) => TranslationHelper.get(s.title, appContext).toLowerCase().contains(searchValue.toString().toLowerCase())).toList();
|
||||
} else {
|
||||
if(searchNumberValue != null) {
|
||||
sectionsToDisplay = sections.where((s) => s!.order!+1 == searchNumberValue).toList();
|
||||
sectionsToDisplay = sections.where((s) => s.order!+1 == searchNumberValue).toList();
|
||||
} else {
|
||||
sectionsToDisplay = sections;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class SectionCard extends StatelessWidget {
|
||||
ResourceModel? resourceModel;
|
||||
|
||||
getResource(String? imageId) async {
|
||||
await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, sectionDTO!.imageId!).then((value) {
|
||||
await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, sectionDTO.imageId!).then((value) {
|
||||
resourceModel = DatabaseHelper.instance.getResourceFromDB(value.first);
|
||||
});
|
||||
}
|
||||
@ -124,7 +124,7 @@ class SectionCard extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
|
||||
child: Text(
|
||||
sectionDTO != null ? TranslationHelper.get(sectionDTO!.title, appContext) : "",
|
||||
TranslationHelper.get(sectionDTO.title, appContext),
|
||||
style: Theme.of(context).textTheme.button,
|
||||
),
|
||||
),
|
||||
|
||||
@ -5,48 +5,56 @@ List<Translation> translations = [
|
||||
"visitTitle": "Liste des visites",
|
||||
"visitDownloadWarning": "Pour suivre cette visite, il faut d'abord la télécharger",
|
||||
"noData": "Pas de données",
|
||||
"invalidQRCode": "code QR invalide"
|
||||
"invalidQRCode": "code QR invalide",
|
||||
"languageNotSupported": "Cette visite ne prend pas en charge votre langue"
|
||||
}),
|
||||
Translation(language: "EN", data: {
|
||||
"visitTitle": "List of tours",
|
||||
"visitDownloadWarning": "To follow this tour, you must first download it",
|
||||
"noData": "No data",
|
||||
"invalidQRCode": "Invalid QR code"
|
||||
"invalidQRCode": "Invalid QR code",
|
||||
"languageNotSupported": "This tour doesn't support your language"
|
||||
}),
|
||||
Translation(language: "DE", data: {
|
||||
"visitTitle": "Liste der Touren",
|
||||
"visitDownloadWarning": "Um dieser Tour zu folgen, müssen Sie sie zuerst herunterladen",
|
||||
"noData": "keine Daten",
|
||||
"invalidQRCode": "Ungültiger QR-Code"
|
||||
"invalidQRCode": "Ungültiger QR-Code",
|
||||
"languageNotSupported": "Diese Tour unterstützt Ihre Sprache nicht"
|
||||
}),
|
||||
Translation(language: "NL", data: {
|
||||
"visitTitle": "Lijst met rondleidingen",
|
||||
"visitDownloadWarning": "Om deze tour te volgen, moet je deze eerst downloaden",
|
||||
"noData": "Geen gegevens",
|
||||
"invalidQRCode": "Ongeldige QR-code"
|
||||
"invalidQRCode": "Ongeldige QR-code",
|
||||
"languageNotSupported": "Deze tour ondersteunt je taal niet"
|
||||
}),
|
||||
Translation(language: "IT", data: {
|
||||
"visitTitle": "Elenco dei tour",
|
||||
"visitDownloadWarning": "Per seguire questo tour, devi prima scaricarlo",
|
||||
"noData": "Nessun dato",
|
||||
"invalidQRCode": "Codice QR non valido"
|
||||
"invalidQRCode": "Codice QR non valido",
|
||||
"languageNotSupported": "Questo tour non supporta la tua lingua"
|
||||
}),
|
||||
Translation(language: "ES", data: {
|
||||
"visitTitle": "Lista de recorridos",
|
||||
"visitDownloadWarning": "Para realizar este recorrido, primero debe descargarlo",
|
||||
"noData": "Sin datos",
|
||||
"invalidQRCode": "Código QR no válido"
|
||||
"invalidQRCode": "Código QR no válido",
|
||||
"languageNotSupported": "Este tour no es compatible con tu idioma"
|
||||
}),
|
||||
Translation(language: "PL", data: {
|
||||
"visitTitle": "Lista wycieczek",
|
||||
"visitDownloadWarning": "Aby wziąć udział w tej wycieczce, musisz ją najpierw pobrać",
|
||||
"noData": "Brak danych",
|
||||
"invalidQRCode": "Nieprawidłowy kod QR"
|
||||
"invalidQRCode": "Nieprawidłowy kod QR",
|
||||
"languageNotSupported": "Ta wycieczka nie obsługuje Twojego języka"
|
||||
}),
|
||||
Translation(language: "CN", data: {
|
||||
"visitTitle": "旅游清单",
|
||||
"visitDownloadWarning": "要参加此导览,您需要先下载它",
|
||||
"noData": "没有数据",
|
||||
"invalidQRCode": "二维码无效"
|
||||
"invalidQRCode": "二维码无效",
|
||||
"languageNotSupported": "此导览不支持您的语言"
|
||||
}),
|
||||
];
|
||||
Loading…
x
Reference in New Issue
Block a user