96 lines
3.3 KiB
Dart
96 lines
3.3 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_api/api.dart';
|
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
|
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
|
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/networkCheck.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
|
import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
|
import 'package:mymuseum_visitapp/Screens/Scanner/scanner_old.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
import 'package:mymuseum_visitapp/client.dart';
|
|
import 'package:mymuseum_visitapp/constants.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ArticlePage extends StatefulWidget {
|
|
const ArticlePage({Key? key, required this.articleId}) : super(key: key);
|
|
|
|
final String articleId;
|
|
|
|
@override
|
|
State<ArticlePage> createState() => _ArticlePageState();
|
|
}
|
|
|
|
class _ArticlePageState extends State<ArticlePage> {
|
|
SectionDTO? sectionDTO;
|
|
ArticleDTO? articleDTO;
|
|
ResourceModel? resourceModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: "ArticlePage",
|
|
isHomeButton: false,
|
|
),
|
|
body: FutureBuilder(
|
|
future: getArticle(appContext.clientAPI, widget.articleId),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if(articleDTO != null && sectionDTO != null) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(TranslationHelper.get(sectionDTO!.title, appContext)),
|
|
Text(
|
|
TranslationHelper.get(articleDTO!.content, appContext),
|
|
style: Theme.of(context).textTheme.headline4,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
resourceModel != null ? Image.memory(base64Decode(resourceModel!.data!)) : const Text("image"),
|
|
],
|
|
),
|
|
);
|
|
} else {
|
|
return const Loading();
|
|
}
|
|
|
|
}
|
|
),
|
|
floatingActionButton: const ScannerBouton(isReplacement: true),
|
|
);
|
|
}
|
|
|
|
Future<ArticleDTO?> getArticle(Client client, String articleId) async {
|
|
try {
|
|
bool isOnline = await hasNetwork();
|
|
if(true) {
|
|
await DatabaseHelper.instance.queryWithId(DatabaseTableType.sections, articleId).then((value) async {
|
|
sectionDTO = DatabaseHelper.instance.getSectionFromDB(value.first);
|
|
if(sectionDTO!.type == SectionType.Article) {
|
|
articleDTO = ArticleDTO.fromJson(jsonDecode(sectionDTO!.data!));
|
|
if(articleDTO!.images!.isNotEmpty) {
|
|
await DatabaseHelper.instance.queryWithId(DatabaseTableType.resources, articleDTO!.images!.first.resourceId!).then((value) {
|
|
resourceModel = DatabaseHelper.instance.getResourceFromDB(value.first);
|
|
});
|
|
}
|
|
}
|
|
|
|
});
|
|
} else {
|
|
// TODO ONLINE
|
|
return null; // TODO return local list..
|
|
}
|
|
} catch (e) {
|
|
print(e);
|
|
print("IN CATCH");
|
|
return null;
|
|
}
|
|
}
|
|
}
|