155 lines
7.1 KiB
Dart
155 lines
7.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
|
import 'package:mymuseum_visitapp/Components/SearchBox.dart';
|
|
import 'package:mymuseum_visitapp/Components/SearchNumberBox.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
|
import 'package:mymuseum_visitapp/Models/beaconSection.dart';
|
|
import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
|
import 'package:mymuseum_visitapp/Screens/Sections/Article/article_page.dart';
|
|
import 'package:mymuseum_visitapp/Services/apiService.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
import 'package:mymuseum_visitapp/client.dart';
|
|
import 'package:mymuseum_visitapp/constants.dart';
|
|
import 'package:photo_view/photo_view.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
class BeaconArticleFound extends StatefulWidget {
|
|
const BeaconArticleFound({Key? key, required this.beaconSection}) : super(key: key);
|
|
|
|
final BeaconSection? beaconSection;
|
|
|
|
@override
|
|
State<BeaconArticleFound> createState() => _BeaconArticleFoundState();
|
|
}
|
|
|
|
class _BeaconArticleFoundState extends State<BeaconArticleFound> {
|
|
late VisitAppContext visitAppContext;
|
|
SectionDTO? sectionFound;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
visitAppContext = appContext.getContext();
|
|
|
|
if(widget.beaconSection != null && visitAppContext.currentSections != null && visitAppContext.currentSections!.isNotEmpty)
|
|
{
|
|
var testSection = visitAppContext.currentSections!.where((section) => section!.id.toString() == widget.beaconSection!.sectionId.toString()).toList();
|
|
sectionFound = testSection.isNotEmpty ? testSection.first : null;
|
|
}
|
|
|
|
return FutureBuilder(
|
|
future: getSectionImage(appContext, visitAppContext.clientAPI, sectionFound),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
return SizedBox(
|
|
height: size.height *0.4,
|
|
width: size.width *0.9,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
if(snapshot.data != null && ((visitAppContext.configuration!.isOffline! && snapshot.data!.path != null) || (visitAppContext.configuration!.isOffline! && snapshot.data!.source != null)))
|
|
SizedBox(
|
|
height: size.height * 0.25,
|
|
width: size.width * 0.75,
|
|
child: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
|
child: ClipRRect(
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
child: visitAppContext.configuration!.isOffline! ?
|
|
snapshot.data != null ?
|
|
Image.file(
|
|
snapshot.data!,
|
|
fit: BoxFit.cover,
|
|
) : null :
|
|
Image.network(
|
|
snapshot.data!.source!,
|
|
fit: BoxFit.cover,
|
|
loadingBuilder: (BuildContext context, Widget child,
|
|
ImageChunkEvent? loadingProgress) {
|
|
if (loadingProgress == null) {
|
|
return child;
|
|
}
|
|
return Center(
|
|
child: CircularProgressIndicator(
|
|
color: kMainColor1,
|
|
value: loadingProgress.expectedTotalBytes != null
|
|
? loadingProgress.cumulativeBytesLoaded /
|
|
loadingProgress.expectedTotalBytes!
|
|
: null,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.center,
|
|
child: HtmlWidget(
|
|
TranslationHelper.get(sectionFound!.title, appContext.getContext()),
|
|
textStyle: const TextStyle(fontSize: kMenuTitleDetailSize),
|
|
customStylesBuilder: (element) {
|
|
return {'text-align': 'center'};
|
|
},
|
|
//textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
/*Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text("Non"),
|
|
Text("Ouvrir")
|
|
],
|
|
)*/
|
|
],
|
|
)
|
|
),
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
Future<dynamic> getSectionImage(AppContext appContext, Client clientAPI, SectionDTO? sectionFound) async {
|
|
if(sectionFound == null) {
|
|
return null;
|
|
}
|
|
bool isConfigOffline = (appContext.getContext() as VisitAppContext).configuration!.isOffline!;
|
|
if(isConfigOffline) {
|
|
List<Map<String, dynamic>> resource = await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, sectionFound.imageId!);
|
|
if(resource.isNotEmpty) {
|
|
Directory? appDocumentsDirectory = Platform.isIOS ? await getApplicationDocumentsDirectory() : await getDownloadsDirectory();
|
|
String localPath = appDocumentsDirectory!.path;
|
|
Directory configurationDirectory = Directory('$localPath/${sectionFound.configurationId}');
|
|
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
|
|
|
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(sectionFound.imageId!))) {
|
|
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(sectionFound.imageId!)).path);
|
|
return file;
|
|
}
|
|
return null;
|
|
} else {
|
|
print("EMPTY resourcesModel - getSectionImage");
|
|
return null;
|
|
}
|
|
} else {
|
|
// ONLINE
|
|
return ResourceModel(id: sectionFound.imageId, source: sectionFound.imageSource, type: ResourceType.Image);
|
|
}
|
|
}
|
|
|
|
}
|