misc + wip load section (not working)
This commit is contained in:
parent
b7ca69162c
commit
9c5ae56549
@ -185,7 +185,7 @@ class _ScannerDialogState extends State<ScannerDialog> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return SectionPage(visitAppContextIn: visitAppContext, sectionId: section.id!);
|
return SectionPage(configuration: visitAppContext.configuration!, rawSection: null, visitAppContextIn: visitAppContext, sectionId: section.id!);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
24
lib/Components/SlideFromRouteRight.dart
Normal file
24
lib/Components/SlideFromRouteRight.dart
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SlideFromRightRoute extends PageRouteBuilder {
|
||||||
|
final Widget page;
|
||||||
|
|
||||||
|
SlideFromRightRoute({required this.page})
|
||||||
|
: super(
|
||||||
|
pageBuilder: (context, animation, secondaryAnimation) => page,
|
||||||
|
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||||
|
const begin = Offset(1.0, 0.0); // départ à droite (hors écran)
|
||||||
|
const end = Offset.zero; // arrivée position normale
|
||||||
|
const curve = Curves.easeInOut;
|
||||||
|
|
||||||
|
final tween =
|
||||||
|
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
|
||||||
|
final offsetAnimation = animation.drive(tween);
|
||||||
|
|
||||||
|
return SlideTransition(
|
||||||
|
position: offsetAnimation,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class FadeRoute extends PageRouteBuilder {
|
|
||||||
final Widget page;
|
|
||||||
|
|
||||||
FadeRoute({required this.page})
|
|
||||||
: super(
|
|
||||||
pageBuilder: (context, animation, secondaryAnimation) => page,
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
const begin = 0.0;
|
|
||||||
const end = 1.0;
|
|
||||||
const curve = Curves.easeInOut;
|
|
||||||
|
|
||||||
final tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
|
|
||||||
final opacityAnimation = animation.drive(tween);
|
|
||||||
|
|
||||||
return FadeTransition(
|
|
||||||
opacity: opacityAnimation,
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -6,7 +6,7 @@ import 'package:mymuseum_visitapp/Models/resourceModel.dart';
|
|||||||
import 'package:mymuseum_visitapp/client.dart';
|
import 'package:mymuseum_visitapp/client.dart';
|
||||||
|
|
||||||
class VisitAppContext with ChangeNotifier {
|
class VisitAppContext with ChangeNotifier {
|
||||||
Client clientAPI = Client("http://192.168.31.228:5000"); // Replace by https://api.mymuseum.be //http://192.168.31.140:8089 // https://api.myinfomate.be
|
Client clientAPI = Client("https://api.mymuseum.be"); // Replace by https://api.mymuseum.be //http://192.168.31.140:8089 // https://api.myinfomate.be // http://192.168.31.228:5000
|
||||||
|
|
||||||
String? id = "";
|
String? id = "";
|
||||||
String? language = "";
|
String? language = "";
|
||||||
|
|||||||
@ -35,16 +35,20 @@ class ArticlePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ArticlePageState extends State<ArticlePage> {
|
class _ArticlePageState extends State<ArticlePage> {
|
||||||
SectionDTO? sectionDTO;
|
|
||||||
ArticleDTO? articleDTO;
|
|
||||||
ResourceModel? audioResourceModel;
|
ResourceModel? audioResourceModel;
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
File? audioFile;
|
File? audioFile;
|
||||||
late VisitAppContext visitAppContext;
|
late VisitAppContext visitAppContext;
|
||||||
|
late List<ResourceModel?> resourcesModelToShow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
widget.visitAppContextIn.isContentCurrentlyShown = true;
|
widget.visitAppContextIn.isContentCurrentlyShown = true;
|
||||||
|
|
||||||
|
audioResourceModel = widget.resourcesModel.firstWhere((r) => r?.type == ResourceType.Audio, orElse: () => null);
|
||||||
|
|
||||||
|
resourcesModelToShow = widget.resourcesModel.where((r) => r?.type != ResourceType.Audio).toList(); // TODO also handle audio in slider .. must differentiate the main audio and the rest
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,24 +69,23 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: CustomAppBar(
|
appBar: CustomAppBar(
|
||||||
title: sectionDTO != null ? TranslationHelper.get(sectionDTO!.title, visitAppContext) : "",
|
title: TranslationHelper.get(widget.articleDTO.title, visitAppContext),
|
||||||
isHomeButton: false,
|
isHomeButton: false,
|
||||||
isTextSizeButton: true,
|
isTextSizeButton: true,
|
||||||
),
|
),
|
||||||
body: OrientationBuilder(
|
body: OrientationBuilder(
|
||||||
builder: (context, orientation) {
|
builder: (context, orientation) {
|
||||||
if(articleDTO != null && sectionDTO != null) {
|
|
||||||
if(size.height > size.width) {
|
if(size.height > size.width) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if(articleDTO!.isContentTop!)
|
if(widget.articleDTO.isContentTop!)
|
||||||
getContent(size, appContext),
|
getContent(size, appContext),
|
||||||
if(articleDTO!.isContentTop! && widget.resourcesModel.isNotEmpty)
|
if(widget.articleDTO.isContentTop! && resourcesModelToShow.isNotEmpty)
|
||||||
getImages(size, articleDTO!.isContentTop!),
|
getImages(size, widget.articleDTO.isContentTop!),
|
||||||
|
|
||||||
if(!articleDTO!.isContentTop! && widget.resourcesModel.isNotEmpty)
|
if(!widget.articleDTO.isContentTop! && resourcesModelToShow.isNotEmpty)
|
||||||
getImages(size, articleDTO!.isContentTop!),
|
getImages(size, widget.articleDTO.isContentTop!),
|
||||||
if(!articleDTO!.isContentTop!)
|
if(!widget.articleDTO.isContentTop!)
|
||||||
getContent(size, appContext),
|
getContent(size, appContext),
|
||||||
|
|
||||||
/*if(audioResourceModel != null)
|
/*if(audioResourceModel != null)
|
||||||
@ -98,14 +101,14 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
if(articleDTO!.isContentTop!)
|
if(widget.articleDTO.isContentTop!)
|
||||||
getContent(size, appContext),
|
getContent(size, appContext),
|
||||||
if(articleDTO!.isContentTop! && widget.resourcesModel.isNotEmpty)
|
if(widget.articleDTO.isContentTop! && resourcesModelToShow.isNotEmpty)
|
||||||
getImages(size, articleDTO!.isContentTop!),
|
getImages(size, widget.articleDTO.isContentTop!),
|
||||||
|
|
||||||
if(!articleDTO!.isContentTop! && widget.resourcesModel.isNotEmpty)
|
if(!widget.articleDTO.isContentTop! && resourcesModelToShow.isNotEmpty)
|
||||||
getImages(size, articleDTO!.isContentTop!),
|
getImages(size, widget.articleDTO.isContentTop!),
|
||||||
if(!articleDTO!.isContentTop!)
|
if(!widget.articleDTO.isContentTop!)
|
||||||
getContent(size, appContext),
|
getContent(size, appContext),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -115,14 +118,11 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return const LoadingCommon();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
floatingActionButton: Padding(
|
floatingActionButton: Padding(
|
||||||
padding: const EdgeInsets.only(right: 0, top: 0), //size.height*0.1
|
padding: const EdgeInsets.only(right: 0, top: 0), //size.height*0.1
|
||||||
child: audioResourceModel != null && audioResourceModel!.source != null ? AudioPlayerFloatingContainer(file: audioFile, resourceURl: audioResourceModel!.source!, isAuto: articleDTO!.isReadAudioAuto!) : null,
|
child: audioResourceModel != null && audioResourceModel!.source != null ? AudioPlayerFloatingContainer(file: audioFile, resourceURl: audioResourceModel!.source!, isAuto: widget.articleDTO.isReadAudioAuto!) : null,
|
||||||
),
|
),
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat, //miniEndTop
|
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat, //miniEndTop
|
||||||
);
|
);
|
||||||
@ -147,9 +147,9 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
boxShadow: const [kDefaultShadow],
|
boxShadow: const [kDefaultShadow],
|
||||||
),
|
),
|
||||||
child: SliderImagesWidget(
|
child: SliderImagesWidget(
|
||||||
resources: widget.resourcesModel,
|
resources: resourcesModelToShow,
|
||||||
height: size.height * 0.29,
|
height: size.height * 0.29,
|
||||||
contentsDTO: articleDTO!.contents!,
|
contentsDTO: widget.articleDTO.contents!,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -172,9 +172,9 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
boxShadow: const [kDefaultShadow],
|
boxShadow: const [kDefaultShadow],
|
||||||
),
|
),
|
||||||
child: SliderImagesWidget(
|
child: SliderImagesWidget(
|
||||||
resources: widget.resourcesModel,
|
resources: resourcesModelToShow,
|
||||||
height: size.height * 0.29,
|
height: size.height * 0.29,
|
||||||
contentsDTO: articleDTO!.contents!,
|
contentsDTO: widget.articleDTO.contents!,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -206,7 +206,7 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: HtmlWidget(
|
child: HtmlWidget(
|
||||||
TranslationHelper.get(articleDTO!.content, appContext.getContext()),
|
TranslationHelper.get(widget.articleDTO.content, appContext.getContext()),
|
||||||
textStyle: TextStyle(fontSize: (appContext.getContext() as VisitAppContext).isMaximizeTextSize ? kArticleContentBiggerSize : kArticleContentSize),
|
textStyle: TextStyle(fontSize: (appContext.getContext() as VisitAppContext).isMaximizeTextSize ? kArticleContentBiggerSize : kArticleContentSize),
|
||||||
customStylesBuilder: (element)
|
customStylesBuilder: (element)
|
||||||
{
|
{
|
||||||
@ -243,7 +243,7 @@ class _ArticlePageState extends State<ArticlePage> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: HtmlWidget(
|
child: HtmlWidget(
|
||||||
TranslationHelper.get(articleDTO!.content, appContext.getContext()),
|
TranslationHelper.get(widget.articleDTO.content, appContext.getContext()),
|
||||||
//textAlign: TextAlign.left,
|
//textAlign: TextAlign.left,
|
||||||
textStyle: TextStyle(fontSize: (appContext.getContext() as VisitAppContext).isMaximizeTextSize ? kArticleContentBiggerSize : kArticleContentSize, fontFamily: "Arial"),
|
textStyle: TextStyle(fontSize: (appContext.getContext() as VisitAppContext).isMaximizeTextSize ? kArticleContentBiggerSize : kArticleContentSize, fontFamily: "Arial"),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -43,14 +43,6 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
List<String?> alreadyDownloaded = [];
|
List<String?> alreadyDownloaded = [];
|
||||||
late VisitAppContext visitAppContext;
|
late VisitAppContext visitAppContext;
|
||||||
|
|
||||||
final List<Color> colors = [
|
|
||||||
Colors.blue,
|
|
||||||
Colors.green,
|
|
||||||
Colors.orange,
|
|
||||||
Colors.purple,
|
|
||||||
Colors.teal,
|
|
||||||
Colors.red,
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -128,8 +120,9 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black26,
|
color: Colors.black26,
|
||||||
blurRadius: 3.5,
|
spreadRadius: 0.35,
|
||||||
offset: Offset(0, -20),
|
blurRadius: 2,
|
||||||
|
offset: Offset(0, -22),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -144,7 +137,7 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
Opacity(
|
Opacity(
|
||||||
opacity: 0.85,
|
opacity: 0.85,
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
configurations[1].imageSource!,
|
configurations[0].imageSource!,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -190,9 +183,6 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Update context (it's in visit now, hero..
|
|
||||||
|
|
||||||
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
VisitPage(configuration: configurations[index], isAlreadyAllowed: visitAppContext.isScanBeaconAlreadyAllowed),
|
VisitPage(configuration: configurations[index], isAlreadyAllowed: visitAppContext.isScanBeaconAlreadyAllowed),
|
||||||
@ -200,38 +190,58 @@ class _HomePage3State extends State<HomePage3> with WidgetsBindingObserver {
|
|||||||
},
|
},
|
||||||
child: Hero(
|
child: Hero(
|
||||||
tag: configurations[index].id!,
|
tag: configurations[index].id!,
|
||||||
child: Container(
|
child: Material(
|
||||||
height: 200 + (index % 3) * 55,
|
type: MaterialType.transparency,
|
||||||
decoration: BoxDecoration(
|
child: Container(
|
||||||
color: colors[index % colors.length],
|
height: 200 + (index % 3) * 55,
|
||||||
borderRadius: BorderRadius.circular(16),
|
decoration: BoxDecoration(
|
||||||
boxShadow: const [
|
color: kSecondGrey,
|
||||||
BoxShadow(
|
borderRadius: BorderRadius.circular(16),
|
||||||
color: kMainGrey,
|
boxShadow: const [
|
||||||
spreadRadius: 0.5,
|
BoxShadow(
|
||||||
blurRadius: 5,
|
color: kMainGrey,
|
||||||
offset: Offset(0, 1), // changes position of shadow
|
spreadRadius: 0.5,
|
||||||
),
|
blurRadius: 5,
|
||||||
],
|
offset: Offset(0, 1), // changes position of shadow
|
||||||
image: configurations[index].imageSource != null ? DecorationImage(
|
),
|
||||||
fit: BoxFit.cover,
|
],
|
||||||
opacity: 0.5,
|
image: configurations[index].imageSource != null ? DecorationImage(
|
||||||
image: NetworkImage(
|
fit: BoxFit.cover,
|
||||||
configurations[index].imageSource!,
|
opacity: 0.5,
|
||||||
),
|
image: NetworkImage(
|
||||||
): null,
|
configurations[index].imageSource!,
|
||||||
),
|
),
|
||||||
child: Center(
|
): null,
|
||||||
child: Padding(
|
),
|
||||||
padding: const EdgeInsets.all(8.0),
|
child: Stack(
|
||||||
child: HtmlWidget(
|
children: [
|
||||||
cleanedTitle,
|
Center(
|
||||||
textStyle: const TextStyle(color: Colors.white, fontFamily: 'Roboto', fontSize: 20),
|
child: Padding(
|
||||||
customStylesBuilder: (element)
|
padding: const EdgeInsets.all(8.0),
|
||||||
{
|
child: HtmlWidget(
|
||||||
return {'text-align': 'center', 'font-family': "Roboto", '-webkit-line-clamp': "2"};
|
cleanedTitle,
|
||||||
},
|
textStyle: const TextStyle(color: Colors.white, fontFamily: 'Roboto', fontSize: 20),
|
||||||
),
|
customStylesBuilder: (element)
|
||||||
|
{
|
||||||
|
return {'text-align': 'center', 'font-family': "Roboto", '-webkit-line-clamp': "2"};
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 10,
|
||||||
|
right: 10,
|
||||||
|
child: Container(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
//color: kMainColor,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.chevron_right, size: 18, color: Colors.white)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -58,8 +58,8 @@ class _QuestionsListWidget extends State<QuestionsListWidget> {
|
|||||||
MediaQuery.of(context).size.height * 0.85 :
|
MediaQuery.of(context).size.height * 0.85 :
|
||||||
MediaQuery.of(context).size.height * 0.75 :
|
MediaQuery.of(context).size.height * 0.75 :
|
||||||
widget.orientation == Orientation.portrait ?
|
widget.orientation == Orientation.portrait ?
|
||||||
MediaQuery.of(context).size.height :
|
MediaQuery.of(context).size.height * 0.88:
|
||||||
MediaQuery.of(context).size.height,
|
MediaQuery.of(context).size.height * 0.88,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
//color: Colors.orange,
|
//color: Colors.orange,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
|||||||
@ -4,10 +4,9 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
//import 'package:confetti/confetti.dart';
|
//import 'package:confetti/confetti.dart';
|
||||||
import 'package:flutter/material.dart';
|
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:manager_api_new/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Components/loading_common.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Components/rounded_button.dart';
|
import 'package:mymuseum_visitapp/Components/rounded_button.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
||||||
@ -35,14 +34,12 @@ class QuizPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _QuizPageState extends State<QuizPage> {
|
class _QuizPageState extends State<QuizPage> {
|
||||||
SectionDTO? sectionDTO;
|
|
||||||
List<ResourceModel?> resourcesModel = <ResourceModel?>[];
|
List<ResourceModel?> resourcesModel = <ResourceModel?>[];
|
||||||
ResourceModel? audioResourceModel;
|
ResourceModel? audioResourceModel;
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
late Uint8List audiobytes;
|
late Uint8List audiobytes;
|
||||||
late VisitAppContext visitAppContext;
|
late VisitAppContext visitAppContext;
|
||||||
|
|
||||||
QuizDTO? quizDTO;
|
|
||||||
List<QuestionSubDTO> _questionsSubDTO = <QuestionSubDTO>[];
|
List<QuestionSubDTO> _questionsSubDTO = <QuestionSubDTO>[];
|
||||||
//ConfettiController? _controllerCenter;
|
//ConfettiController? _controllerCenter;
|
||||||
int currentIndex = 1;
|
int currentIndex = 1;
|
||||||
@ -59,6 +56,10 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
//_controllerCenter = ConfettiController(duration: const Duration(seconds: 10));
|
//_controllerCenter = ConfettiController(duration: const Duration(seconds: 10));
|
||||||
//_controllerCenter!.play();
|
//_controllerCenter!.play();
|
||||||
|
|
||||||
|
if(widget.quizDTO.questions != null) {
|
||||||
|
_questionsSubDTO = QuestionSubDTO().fromJSON(widget.quizDTO.questions!);
|
||||||
|
}
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +68,9 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
visitAppContext.isContentCurrentlyShown = false;
|
visitAppContext.isContentCurrentlyShown = false;
|
||||||
currentIndex = 1;
|
currentIndex = 1;
|
||||||
//_controllerCenter!.dispose();
|
//_controllerCenter!.dispose();
|
||||||
if(quizDTO != null) {
|
|
||||||
if(quizDTO!.questions != null) {
|
if(widget.quizDTO.questions != null) {
|
||||||
_questionsSubDTO = QuestionSubDTO().fromJSON(quizDTO!.questions!);
|
_questionsSubDTO = QuestionSubDTO().fromJSON(widget.quizDTO.questions!);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@ -84,136 +84,187 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: CustomAppBar(
|
/*appBar: CustomAppBar(
|
||||||
title: sectionDTO != null ? TranslationHelper.get(sectionDTO!.title, visitAppContext) : "",
|
title: TranslationHelper.get(widget.quizDTO.title, visitAppContext),
|
||||||
isHomeButton: false,
|
isHomeButton: false,
|
||||||
),
|
),*/
|
||||||
body: OrientationBuilder(
|
body: Column(
|
||||||
builder: (context, orientation) {
|
children: [
|
||||||
if(quizDTO != null && sectionDTO != null) {
|
Stack(
|
||||||
|
fit: StackFit.passthrough,
|
||||||
if(showResult) {
|
children: [
|
||||||
var goodResponses = 0;
|
Container(
|
||||||
for (var question in _questionsSubDTO) {
|
height: size.height * 0.12,
|
||||||
if(question.chosen == question.responsesSubDTO!.indexWhere((response) => response.isGood!)) {
|
width: size.width,
|
||||||
goodResponses +=1;
|
decoration: BoxDecoration(
|
||||||
}
|
boxShadow: const [
|
||||||
}
|
BoxShadow(
|
||||||
log("goodResponses =" + goodResponses.toString());
|
color: kMainGrey,
|
||||||
List<TranslationAndResourceDTO> levelToShow = [];
|
spreadRadius: 0.5,
|
||||||
var test = goodResponses/quizDTO!.questions!.length;
|
blurRadius: 2,
|
||||||
|
offset: Offset(0, 1), // changes position of shadow
|
||||||
if((0 == test || test < 0.25) && quizDTO!.badLevel != null) {
|
),
|
||||||
levelToShow = quizDTO!.badLevel!;
|
|
||||||
}
|
|
||||||
if((test>=0.25 && test < 0.5) && quizDTO!.mediumLevel != null) {
|
|
||||||
levelToShow = quizDTO!.mediumLevel!;
|
|
||||||
}
|
|
||||||
if((test>=0.5 && test < 0.75) && quizDTO!.goodLevel != null) {
|
|
||||||
levelToShow = quizDTO!.goodLevel!;
|
|
||||||
}
|
|
||||||
if((test>=0.75 && test <= 1) && quizDTO!.greatLevel != null) {
|
|
||||||
levelToShow = quizDTO!.greatLevel!;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
/*Center(
|
|
||||||
child: SizedBox(
|
|
||||||
width: 5,
|
|
||||||
height: 5,
|
|
||||||
child: ConfettiWidget(
|
|
||||||
confettiController: _controllerCenter!,
|
|
||||||
blastDirectionality: BlastDirectionality.explosive,
|
|
||||||
shouldLoop: false, // start again as soon as the animation is finished
|
|
||||||
colors: const [
|
|
||||||
kMainColor,
|
|
||||||
kSecondColor,
|
|
||||||
kConfigurationColor,
|
|
||||||
kMainColor1
|
|
||||||
//Colors.pink,
|
|
||||||
//Colors.orange,
|
|
||||||
//Colors.purple
|
|
||||||
], // manually specify the colors to be used
|
|
||||||
createParticlePath: drawPath, // define a custom shape/path.
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),*/
|
|
||||||
if (orientation == Orientation.portrait)
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
if (!showResponses && levelToShow.firstWhere((label) => label.language == visitAppContext.language).resource?.url != null) // TODO SUPPORT OTHER THAN IMAGES
|
|
||||||
resultImage(visitAppContext, size, levelToShow, orientation),
|
|
||||||
if(!showResponses)
|
|
||||||
// TEXT BOX WITH MAIN SCORE
|
|
||||||
Text('$goodResponses/${quizDTO!.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? (showResponses ? 60 : 100) : 75, color: kBackgroundSecondGrey)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
if (orientation == Orientation.landscape)
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
if(!showResponses)
|
|
||||||
// TEXT BOX WITH MAIN SCORE
|
|
||||||
Text('$goodResponses/${quizDTO!.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? (showResponses ? 60 : 100) : 75, color: kBackgroundSecondGrey)),
|
|
||||||
if (!showResponses && levelToShow.firstWhere((label) => label.language == visitAppContext.language).resource?.url != null)
|
|
||||||
resultImage(visitAppContext, size, levelToShow, orientation),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
if(!showResponses)
|
|
||||||
// TEXT BOX WITH LEVEL TEXT RESULT
|
|
||||||
resultText(size, levelToShow, appContext),
|
|
||||||
if(showResponses)
|
|
||||||
QuestionsListWidget(
|
|
||||||
questionsSubDTO: _questionsSubDTO,
|
|
||||||
isShowResponse: true,
|
|
||||||
onShowResponse: () {},
|
|
||||||
orientation: orientation,
|
|
||||||
),
|
|
||||||
// RESPONSE BOX
|
|
||||||
//ShowReponsesWidget(questionsSubDTO: _questionsSubDTO),
|
|
||||||
|
|
||||||
if(orientation == Orientation.portrait && !showResponses)
|
|
||||||
// Buttons
|
|
||||||
Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: resultButtons(size, orientation, visitAppContext!),
|
|
||||||
),
|
|
||||||
if(orientation == Orientation.landscape && !showResponses)
|
|
||||||
// Buttons
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: resultButtons(size, orientation, visitAppContext!),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(25),
|
||||||
|
bottomRight: Radius.circular(25),
|
||||||
|
),
|
||||||
|
image: widget.quizDTO.imageSource != null ? DecorationImage(
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
opacity: 0.65,
|
||||||
|
image: NetworkImage(
|
||||||
|
widget.quizDTO.imageSource!,
|
||||||
|
),
|
||||||
|
): null,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 35,
|
||||||
|
left: 10,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: kMainColor,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.arrow_back, size: 23, color: Colors.white)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
OrientationBuilder(
|
||||||
|
builder: (context, orientation) {
|
||||||
|
if(showResult) {
|
||||||
|
var goodResponses = 0;
|
||||||
|
for (var question in _questionsSubDTO) {
|
||||||
|
if(question.chosen == question.responsesSubDTO!.indexWhere((response) => response.isGood!)) {
|
||||||
|
goodResponses +=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("goodResponses =" + goodResponses.toString());
|
||||||
|
List<TranslationAndResourceDTO> levelToShow = [];
|
||||||
|
var test = goodResponses/widget.quizDTO.questions!.length;
|
||||||
|
|
||||||
} else {
|
if((0 == test || test < 0.25) && widget.quizDTO.badLevel != null) {
|
||||||
return QuestionsListWidget(
|
levelToShow = widget.quizDTO.badLevel!;
|
||||||
isShowResponse: false,
|
}
|
||||||
questionsSubDTO: _questionsSubDTO,
|
if((test>=0.25 && test < 0.5) && widget.quizDTO.mediumLevel != null) {
|
||||||
onShowResponse: () {
|
levelToShow = widget.quizDTO.mediumLevel!;
|
||||||
setState(() {
|
}
|
||||||
showResult = true;
|
if((test>=0.5 && test < 0.75) && widget.quizDTO.goodLevel != null) {
|
||||||
});
|
levelToShow = widget.quizDTO.goodLevel!;
|
||||||
},
|
}
|
||||||
orientation: orientation,
|
if((test>=0.75 && test <= 1) && widget.quizDTO.greatLevel != null) {
|
||||||
);
|
levelToShow = widget.quizDTO.greatLevel!;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
/*Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 5,
|
||||||
|
height: 5,
|
||||||
|
child: ConfettiWidget(
|
||||||
|
confettiController: _controllerCenter!,
|
||||||
|
blastDirectionality: BlastDirectionality.explosive,
|
||||||
|
shouldLoop: false, // start again as soon as the animation is finished
|
||||||
|
colors: const [
|
||||||
|
kMainColor,
|
||||||
|
kSecondColor,
|
||||||
|
kConfigurationColor,
|
||||||
|
kMainColor1
|
||||||
|
//Colors.pink,
|
||||||
|
//Colors.orange,
|
||||||
|
//Colors.purple
|
||||||
|
], // manually specify the colors to be used
|
||||||
|
createParticlePath: drawPath, // define a custom shape/path.
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),*/
|
||||||
|
if (orientation == Orientation.portrait)
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
if (!showResponses && levelToShow.firstWhere((label) => label.language == visitAppContext.language).resource?.url != null) // TODO SUPPORT OTHER THAN IMAGES
|
||||||
|
resultImage(visitAppContext, size, levelToShow, orientation),
|
||||||
|
if(!showResponses)
|
||||||
|
// TEXT BOX WITH MAIN SCORE
|
||||||
|
Text('$goodResponses/${widget.quizDTO.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? (showResponses ? 60 : 100) : 75, color: kBackgroundSecondGrey)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
if (orientation == Orientation.landscape)
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
if(!showResponses)
|
||||||
|
// TEXT BOX WITH MAIN SCORE
|
||||||
|
Text('$goodResponses/${widget.quizDTO.questions!.length}', textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? (showResponses ? 60 : 100) : 75, color: kBackgroundSecondGrey)),
|
||||||
|
if (!showResponses && levelToShow.firstWhere((label) => label.language == visitAppContext.language).resource?.url != null)
|
||||||
|
resultImage(visitAppContext, size, levelToShow, orientation),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
if(!showResponses)
|
||||||
|
// TEXT BOX WITH LEVEL TEXT RESULT
|
||||||
|
resultText(size, levelToShow, appContext),
|
||||||
|
if(showResponses)
|
||||||
|
QuestionsListWidget(
|
||||||
|
questionsSubDTO: _questionsSubDTO,
|
||||||
|
isShowResponse: true,
|
||||||
|
onShowResponse: () {},
|
||||||
|
orientation: orientation,
|
||||||
|
),
|
||||||
|
// RESPONSE BOX
|
||||||
|
//ShowReponsesWidget(questionsSubDTO: _questionsSubDTO),
|
||||||
|
|
||||||
|
if(orientation == Orientation.portrait && !showResponses)
|
||||||
|
// Buttons
|
||||||
|
Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: resultButtons(size, orientation, visitAppContext),
|
||||||
|
),
|
||||||
|
if(orientation == Orientation.landscape && !showResponses)
|
||||||
|
// Buttons
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: resultButtons(size, orientation, visitAppContext),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return QuestionsListWidget(
|
||||||
|
isShowResponse: false,
|
||||||
|
questionsSubDTO: _questionsSubDTO,
|
||||||
|
onShowResponse: () {
|
||||||
|
setState(() {
|
||||||
|
showResult = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
orientation: orientation,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
),
|
||||||
return const LoadingCommon();
|
],
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
floatingActionButton: showResponses ? FloatingActionButton(
|
floatingActionButton: showResponses ? FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -221,7 +272,7 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
showResult = false;
|
showResult = false;
|
||||||
showResponses = false;
|
showResponses = false;
|
||||||
currentIndex = 1;
|
currentIndex = 1;
|
||||||
_questionsSubDTO = QuestionSubDTO().fromJSON(quizDTO!.questions!);
|
_questionsSubDTO = QuestionSubDTO().fromJSON(widget.quizDTO.questions!);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
backgroundColor: kBackgroundSecondGrey,
|
backgroundColor: kBackgroundSecondGrey,
|
||||||
@ -378,7 +429,14 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(15.0),
|
padding: const EdgeInsets.all(15.0),
|
||||||
child: Text(TranslationHelper.getWithResource(levelToShow, appContext.getContext() as VisitAppContext), textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kDescriptionSize : kDescriptionSize)),
|
child: HtmlWidget(
|
||||||
|
TranslationHelper.getWithResource(levelToShow, appContext.getContext() as VisitAppContext),textStyle: const TextStyle(fontFamily: 'Roboto', fontSize: 20),
|
||||||
|
customStylesBuilder: (element)
|
||||||
|
{
|
||||||
|
return {'text-align': 'center', 'font-family': "Roboto", '-webkit-line-clamp': "2"};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
//Text(, textAlign: TextAlign.center, style: TextStyle(fontSize: kIsWeb ? kDescriptionSize : kDescriptionSize)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -404,7 +462,7 @@ class _QuizPageState extends State<QuizPage> {
|
|||||||
showResult = false;
|
showResult = false;
|
||||||
showResponses = false;
|
showResponses = false;
|
||||||
currentIndex = 1;
|
currentIndex = 1;
|
||||||
_questionsSubDTO = QuestionSubDTO().fromJSON(quizDTO!.questions!);
|
_questionsSubDTO = QuestionSubDTO().fromJSON(widget.quizDTO.questions!);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:manager_api_new/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Article/article_page.dart';
|
import 'package:mymuseum_visitapp/Screens/Article/article_page.dart';
|
||||||
@ -181,7 +182,7 @@ class _ScannerPageState extends State<ScannerPage> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return SectionPage(sectionId: code, visitAppContextIn: VisitAppContext()); // will not work..
|
return SectionPage(configuration: ConfigurationDTO(), rawSection: null, sectionId: code, visitAppContextIn: VisitAppContext()); // will not work..
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:diacritic/diacritic.dart';
|
import 'package:diacritic/diacritic.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:manager_api_new/api.dart';
|
import 'package:manager_api_new/api.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Components/SlideFromRouteRight.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/loading_common.dart';
|
import 'package:mymuseum_visitapp/Components/loading_common.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/SearchBox.dart';
|
import 'package:mymuseum_visitapp/Components/SearchBox.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/SearchNumberBox.dart';
|
import 'package:mymuseum_visitapp/Components/SearchNumberBox.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Article/article_page.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Screens/Home/home_3.0.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Screens/Quizz/quizz_page.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Screens/section_page.dart';
|
import 'package:mymuseum_visitapp/Screens/section_page.dart';
|
||||||
import 'package:mymuseum_visitapp/Services/apiService.dart';
|
import 'package:mymuseum_visitapp/Services/apiService.dart';
|
||||||
import 'package:mymuseum_visitapp/app_context.dart';
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
@ -28,11 +28,15 @@ class Body extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BodyState extends State<Body> {
|
class _BodyState extends State<Body> {
|
||||||
List<SectionDTO> sections = [];
|
late List<SectionDTO> sections;
|
||||||
|
late List<SectionDTO> _allSections;
|
||||||
|
late List<dynamic> rawSections;
|
||||||
List<SectionDTO> sectionsToDisplay = [];
|
List<SectionDTO> sectionsToDisplay = [];
|
||||||
String? searchValue;
|
String? searchValue;
|
||||||
int? searchNumberValue;
|
int? searchNumberValue;
|
||||||
|
|
||||||
|
final ValueNotifier<List<SectionDTO>> filteredSections = ValueNotifier([]);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
@ -83,21 +87,21 @@ class _BodyState extends State<Body> {
|
|||||||
height: 50,
|
height: 50,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
//setState(() {
|
||||||
visitAppContext.configuration = null;
|
visitAppContext.configuration = null;
|
||||||
visitAppContext.isScanningBeacons = false;
|
visitAppContext.isScanningBeacons = false;
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
/*Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
|
/*Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
|
||||||
builder: (context) => const HomePage3(),
|
builder: (context) => const HomePage3(),
|
||||||
),(route) => false);*/
|
),(route) => false);*/
|
||||||
});
|
//});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: kMainColor,
|
color: kMainColor,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
child: const Icon(Icons.chevron_left, size: 28, color: Colors.white)
|
child: const Icon(Icons.arrow_back, size: 23, color: Colors.white)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@ -108,17 +112,27 @@ class _BodyState extends State<Body> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SearchBox(onChanged: (value) {
|
SearchBox(onChanged: (value) {
|
||||||
setState(() {
|
searchValue = value?.trim();
|
||||||
|
applyFilters(visitAppContext);
|
||||||
|
/*setState(() {
|
||||||
if(value != null && value != "") {
|
if(value != null && value != "") {
|
||||||
searchValue = value;
|
searchValue = value;
|
||||||
} else {
|
} else {
|
||||||
searchValue = null;
|
searchValue = null;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}),
|
}),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SearchNumberBox(onChanged: (value) {
|
child: SearchNumberBox(onChanged: (value) {
|
||||||
setState(() {
|
if (value != null && value.isNotEmpty) {
|
||||||
|
searchNumberValue = int.tryParse(value);
|
||||||
|
} else {
|
||||||
|
searchNumberValue = null;
|
||||||
|
}
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
applyFilters(visitAppContext);
|
||||||
|
}
|
||||||
|
/*setState(() {
|
||||||
if(value != null && value != "") {
|
if(value != null && value != "") {
|
||||||
searchNumberValue = int.parse(value);
|
searchNumberValue = int.parse(value);
|
||||||
} else {
|
} else {
|
||||||
@ -126,7 +140,8 @@ class _BodyState extends State<Body> {
|
|||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
}*/
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -138,10 +153,18 @@ class _BodyState extends State<Body> {
|
|||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.only(top: 0),
|
margin: const EdgeInsets.only(top: 0),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: kMainGrey,
|
||||||
|
spreadRadius: 0.5,
|
||||||
|
blurRadius: 2,
|
||||||
|
offset: Offset(0, 1), // changes position of shadow
|
||||||
|
),
|
||||||
|
],
|
||||||
color: kBackgroundColor,
|
color: kBackgroundColor,
|
||||||
borderRadius: BorderRadius.only(
|
borderRadius: BorderRadius.only(
|
||||||
topLeft: Radius.circular(40),
|
topLeft: Radius.circular(30),
|
||||||
topRight: Radius.circular(40),
|
topRight: Radius.circular(30),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -159,25 +182,31 @@ class _BodyState extends State<Body> {
|
|||||||
// Force refresh if online
|
// Force refresh if online
|
||||||
setState(() {});
|
setState(() {});
|
||||||
} },
|
} },
|
||||||
child: ListView.builder(
|
child: ValueListenableBuilder<List<SectionDTO>>(
|
||||||
itemCount: sectionsToDisplay.length,
|
valueListenable: filteredSections,
|
||||||
itemBuilder: (context, index) => SectionCard(
|
builder: (context, value, child) {
|
||||||
itemCount: sectionsToDisplay.length,
|
return ListView.builder(
|
||||||
itemIndex: index,
|
itemCount: value.length,
|
||||||
sectionDTO: sectionsToDisplay[index],
|
itemBuilder: (context, index) => SectionCard(
|
||||||
press: () {
|
configuration: widget.configuration,
|
||||||
Navigator.push(
|
itemCount: value.length,
|
||||||
context,
|
itemIndex: index,
|
||||||
MaterialPageRoute(
|
sectionDTO: value[index],
|
||||||
builder: (context) => SectionPage(
|
press: () {
|
||||||
visitAppContextIn: appContext.getContext(),
|
Navigator.push(
|
||||||
sectionId: sectionsToDisplay[index].id!,
|
context,
|
||||||
),
|
SlideFromRightRoute(page: SectionPage(
|
||||||
|
configuration: widget.configuration,
|
||||||
|
rawSection: rawSections[index],
|
||||||
|
visitAppContextIn: appContext.getContext(),
|
||||||
|
sectionId: value[index].id!,
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
),
|
)
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||||
@ -212,21 +241,32 @@ class _BodyState extends State<Body> {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ONLINE
|
// ONLINE
|
||||||
List<SectionDTO>? sectionsDownloaded = await ApiService.getAllSections(visitAppContext.clientAPI, widget.configuration.id!);
|
List<dynamic>? sectionsDownloaded = await ApiService.getAllSections(visitAppContext.clientAPI, widget.configuration.id!);
|
||||||
|
rawSections = jsonDecode(jsonEncode(sectionsDownloaded));
|
||||||
|
var rawToSection = jsonDecode(jsonEncode(rawSections)).map((json) => SectionDTO.fromJson(json)).toList();
|
||||||
|
List<SectionDTO> sectionList = rawToSection.whereType<SectionDTO>().toList();
|
||||||
|
|
||||||
//print(sectionsDownloaded);
|
//print(sectionsDownloaded);
|
||||||
if(sectionsDownloaded!.isNotEmpty) {
|
if(sectionList.isNotEmpty) {
|
||||||
sections = sectionsDownloaded.toList();
|
sections = sectionList.toList();
|
||||||
//print(sections);
|
//print(sections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sections = sections.where((s) => s.configurationId == widget.configuration.id!).toList();
|
sections = sections.where((s) => s.configurationId == widget.configuration.id!).toList();
|
||||||
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
||||||
sectionsToDisplay = sections;
|
//sectionsToDisplay = sections;
|
||||||
|
try {
|
||||||
|
_allSections = sections;
|
||||||
|
|
||||||
visitAppContext.currentSections = sectionsToDisplay;
|
//visitAppContext.currentSections = sectionsToDisplay;
|
||||||
|
|
||||||
if(searchValue != '' && searchValue != null) {
|
applyFilters(visitAppContext);
|
||||||
|
} catch(e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(searchValue != '' && searchValue != null) {
|
||||||
sectionsToDisplay = sections.where((s) => removeDiacritics(TranslationHelper.get(s.title, appContext.getContext()).toLowerCase()).contains(removeDiacritics(searchValue.toString().toLowerCase()))).toList();
|
sectionsToDisplay = sections.where((s) => removeDiacritics(TranslationHelper.get(s.title, appContext.getContext()).toLowerCase()).contains(removeDiacritics(searchValue.toString().toLowerCase()))).toList();
|
||||||
} else {
|
} else {
|
||||||
if(searchNumberValue != null) {
|
if(searchNumberValue != null) {
|
||||||
@ -234,6 +274,22 @@ class _BodyState extends State<Body> {
|
|||||||
} else {
|
} else {
|
||||||
sectionsToDisplay = sections;
|
sectionsToDisplay = sections;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyFilters(VisitAppContext visitAppContext) {
|
||||||
|
List<SectionDTO> result = _allSections;
|
||||||
|
|
||||||
|
if (searchValue != null && searchValue!.isNotEmpty) {
|
||||||
|
result = result.where((s) =>
|
||||||
|
removeDiacritics(TranslationHelper.get(s.title, visitAppContext).toLowerCase())
|
||||||
|
.contains(removeDiacritics(searchValue!.toLowerCase()))
|
||||||
|
).toList();
|
||||||
|
} else if (searchNumberValue != null) {
|
||||||
|
result = result.where((s) => s.order! + 1 == searchNumberValue).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredSections.value = result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,14 @@ import 'package:provider/provider.dart';
|
|||||||
class SectionCard extends StatelessWidget {
|
class SectionCard extends StatelessWidget {
|
||||||
const SectionCard({
|
const SectionCard({
|
||||||
Key? key,
|
Key? key,
|
||||||
|
required this.configuration,
|
||||||
required this.itemIndex,
|
required this.itemIndex,
|
||||||
required this.itemCount,
|
required this.itemCount,
|
||||||
required this.sectionDTO,
|
required this.sectionDTO,
|
||||||
required this.press,
|
required this.press,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final ConfigurationDTO configuration;
|
||||||
final int itemIndex;
|
final int itemIndex;
|
||||||
final int itemCount;
|
final int itemCount;
|
||||||
final SectionDTO sectionDTO;
|
final SectionDTO sectionDTO;
|
||||||
@ -33,7 +35,7 @@ class SectionCard extends StatelessWidget {
|
|||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
bool isOffline = (appContext.getContext() as VisitAppContext).configuration?.isOffline! ?? false;
|
bool isOffline = configuration.isOffline! ?? false;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(
|
||||||
@ -69,7 +71,7 @@ class SectionCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if(sectionDTO.imageId != null && (appContext.getContext() as VisitAppContext).configuration != null)
|
if(sectionDTO.imageId != null ) // && (appContext.getContext() as VisitAppContext).configuration != null
|
||||||
// section main image
|
// section main image
|
||||||
Positioned(
|
Positioned(
|
||||||
top: kDefaultPadding +4.0,
|
top: kDefaultPadding +4.0,
|
||||||
@ -82,7 +84,7 @@ class SectionCard extends StatelessWidget {
|
|||||||
// image is square but we add extra 20 + 20 padding thats why width is 200
|
// image is square but we add extra 20 + 20 padding thats why width is 200
|
||||||
width: size.width*0.5,
|
width: size.width*0.5,
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: ApiService.getResource(appContext, (appContext.getContext() as VisitAppContext).configuration!, sectionDTO.imageId!),
|
future: ApiService.getResource(appContext, configuration, sectionDTO.imageId!),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
return ClipRRect(
|
return ClipRRect(
|
||||||
@ -142,10 +144,6 @@ class SectionCard extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
|
padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
|
||||||
child: HtmlWidget(TranslationHelper.get(sectionDTO.title, appContext.getContext()))
|
child: HtmlWidget(TranslationHelper.get(sectionDTO.title, appContext.getContext()))
|
||||||
/*Text(
|
|
||||||
TranslationHelper.get(sectionDTO.title, appContext.getContext()),
|
|
||||||
style: Theme.of(context).textTheme.button,
|
|
||||||
)*/,
|
|
||||||
),
|
),
|
||||||
// it use the available space
|
// it use the available space
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
@ -171,6 +169,16 @@ class SectionCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const Positioned(
|
||||||
|
right: -4,
|
||||||
|
top: (136/2)-18,
|
||||||
|
bottom: 25,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: Icon(Icons.chevron_right, size: 15, color: Colors.white)
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -74,9 +74,12 @@ class _VisitPageState extends State<VisitPage> with WidgetsBindingObserver {
|
|||||||
listeningState();
|
listeningState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
final appContext = Provider.of<AppContext>(context, listen: false);
|
final appContext = Provider.of<AppContext>(context, listen: false);
|
||||||
});*/
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
|
visitAppContext.configuration = widget.configuration;
|
||||||
|
appContext.setContext(visitAppContext);
|
||||||
|
});
|
||||||
//listeningState();
|
//listeningState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,6 +299,8 @@ class _VisitPageState extends State<VisitPage> with WidgetsBindingObserver {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SectionPage(
|
builder: (context) => SectionPage(
|
||||||
|
configuration: widget.configuration,
|
||||||
|
rawSection: null,
|
||||||
visitAppContextIn: visitAppContext,
|
visitAppContextIn: visitAppContext,
|
||||||
sectionId: beaconSection!.sectionId!,
|
sectionId: beaconSection!.sectionId!,
|
||||||
),
|
),
|
||||||
|
|||||||
@ -27,9 +27,11 @@ import 'package:mymuseum_visitapp/constants.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class SectionPage extends StatefulWidget {
|
class SectionPage extends StatefulWidget {
|
||||||
const SectionPage({Key? key, required this.visitAppContextIn, required this.sectionId}) : super(key: key);
|
const SectionPage({Key? key, required this.rawSection, required this.visitAppContextIn, required this.configuration, required this.sectionId}) : super(key: key);
|
||||||
|
|
||||||
|
final Object? rawSection;
|
||||||
final String sectionId;
|
final String sectionId;
|
||||||
|
final ConfigurationDTO configuration;
|
||||||
final VisitAppContext visitAppContextIn;
|
final VisitAppContext visitAppContextIn;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -61,24 +63,27 @@ class _SectionPageState extends State<SectionPage> {
|
|||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
visitAppContext = appContext.getContext();
|
visitAppContext = appContext.getContext();
|
||||||
|
|
||||||
|
var test = SectionDTO.fromJson(jsonDecode(jsonEncode(widget.rawSection)));
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: CustomAppBar(
|
appBar: test!.type != SectionType.Quiz && test.type != SectionType.Article ? CustomAppBar(
|
||||||
title: sectionDTO != null ? TranslationHelper.get(sectionDTO!.title, visitAppContext) : "",
|
title: sectionDTO != null ? TranslationHelper.get(sectionDTO!.title, visitAppContext) : "",
|
||||||
isHomeButton: false,
|
isHomeButton: false,
|
||||||
),
|
) : null,
|
||||||
body: OrientationBuilder(
|
body: OrientationBuilder(
|
||||||
builder: (context, orientation) {
|
builder: (context, orientation) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: getSectionDetail(appContext, visitAppContext.clientAPI, widget.sectionId),
|
future: getSectionDetail(appContext, visitAppContext.clientAPI, widget.sectionId),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if(sectionDTO != null) {
|
var sectionResult = snapshot.data;
|
||||||
|
if(sectionDTO != null && sectionResult != null) {
|
||||||
switch(sectionDTO!.type) {
|
switch(sectionDTO!.type) {
|
||||||
case SectionType.Article:
|
case SectionType.Article:
|
||||||
ArticleDTO articleDTO = ArticleDTO.fromJson(rawSectionData)!;
|
ArticleDTO articleDTO = ArticleDTO.fromJson(sectionResult)!;
|
||||||
return ArticlePage(visitAppContextIn: widget.visitAppContextIn, articleDTO: articleDTO, resourcesModel: resourcesModel);
|
return ArticlePage(visitAppContextIn: widget.visitAppContextIn, articleDTO: articleDTO, resourcesModel: resourcesModel);
|
||||||
case SectionType.Quiz:
|
case SectionType.Quiz:
|
||||||
QuizDTO quizDTO = QuizDTO.fromJson(rawSectionData)!;
|
QuizDTO quizDTO = QuizDTO.fromJson(sectionResult)!;
|
||||||
return QuizPage(visitAppContextIn: widget.visitAppContextIn, quizDTO: quizDTO, resourcesModel: resourcesModel);
|
return QuizPage(visitAppContextIn: widget.visitAppContextIn, quizDTO: quizDTO, resourcesModel: resourcesModel);
|
||||||
default:
|
default:
|
||||||
return const Center(child: Text("Unsupported type"));
|
return const Center(child: Text("Unsupported type"));
|
||||||
@ -95,8 +100,8 @@ class _SectionPageState extends State<SectionPage> {
|
|||||||
|
|
||||||
Future<dynamic> getSectionDetail(AppContext appContext, Client client, String sectionId) async {
|
Future<dynamic> getSectionDetail(AppContext appContext, Client client, String sectionId) async {
|
||||||
try {
|
try {
|
||||||
if(sectionDTO == null) {
|
bool isConfigOffline = widget.configuration.isOffline!;
|
||||||
bool isConfigOffline = (appContext.getContext() as VisitAppContext).configuration!.isOffline!;
|
if(widget.rawSection == null) {
|
||||||
if(isConfigOffline)
|
if(isConfigOffline)
|
||||||
{
|
{
|
||||||
// OFFLINE
|
// OFFLINE
|
||||||
@ -124,48 +129,88 @@ class _SectionPageState extends State<SectionPage> {
|
|||||||
sectionDTO = sectionOnline;
|
sectionDTO = sectionOnline;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(sectionDTO!.type)
|
|
||||||
{
|
|
||||||
case SectionType.Quiz:
|
|
||||||
QuizDTO? quizDTO = QuizDTO.fromJson(jsonDecode(rawSectionData));
|
|
||||||
if(quizDTO != null) {
|
|
||||||
quizDTO.questions!.sort((a, b) => a.order!.compareTo(b.order!));
|
|
||||||
if(quizDTO.questions != null && quizDTO.questions!.isNotEmpty) {
|
|
||||||
quizDTO.questions!.sort((a, b) => a.order!.compareTo(b.order!));
|
|
||||||
for (var question in quizDTO.questions!) {
|
|
||||||
if(isConfigOffline)
|
|
||||||
{
|
|
||||||
// OFFLINE
|
|
||||||
if(question.imageBackgroundResourceId != null) {
|
|
||||||
List<Map<String, dynamic>> ressourceQuizz = await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, question.imageBackgroundResourceId!);
|
|
||||||
if(ressourceQuizz.isNotEmpty) {
|
|
||||||
resourcesModel.add(DatabaseHelper.instance.getResourceFromDB(ressourceQuizz.first));
|
|
||||||
} else {
|
|
||||||
print("EMPTY resourcesModel - second");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ONLINE
|
|
||||||
if(question.imageBackgroundResourceId != null) {
|
|
||||||
resourcesModel.add(ResourceModel(id: question.imageBackgroundResourceId, source: question.imageBackgroundResourceUrl, type: ResourceType.Image));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*setState(() {
|
/*setState(() {
|
||||||
//print(sectionDTO!.title);
|
//print(sectionDTO!.title);
|
||||||
});*/
|
});*/
|
||||||
} else {
|
} else {
|
||||||
return null; // TODO return local list..
|
rawSectionData = widget.rawSection;
|
||||||
|
sectionDTO = SectionDTO.fromJson(jsonDecode(jsonEncode(rawSectionData)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(sectionDTO!.type)
|
||||||
|
{
|
||||||
|
case SectionType.Quiz:
|
||||||
|
QuizDTO? quizDTO = QuizDTO.fromJson(rawSectionData);
|
||||||
|
if(quizDTO != null) {
|
||||||
|
quizDTO.questions!.sort((a, b) => a.order!.compareTo(b.order!));
|
||||||
|
if(quizDTO.questions != null && quizDTO.questions!.isNotEmpty) {
|
||||||
|
quizDTO.questions!.sort((a, b) => a.order!.compareTo(b.order!));
|
||||||
|
for (var question in quizDTO.questions!) {
|
||||||
|
if(isConfigOffline)
|
||||||
|
{
|
||||||
|
// OFFLINE
|
||||||
|
if(question.imageBackgroundResourceId != null) {
|
||||||
|
List<Map<String, dynamic>> ressourceQuizz = await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, question.imageBackgroundResourceId!);
|
||||||
|
if(ressourceQuizz.isNotEmpty) {
|
||||||
|
resourcesModel.add(DatabaseHelper.instance.getResourceFromDB(ressourceQuizz.first));
|
||||||
|
} else {
|
||||||
|
print("EMPTY resourcesModel - second");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ONLINE
|
||||||
|
if(question.imageBackgroundResourceId != null) {
|
||||||
|
resourcesModel.add(ResourceModel(id: question.imageBackgroundResourceId, source: question.imageBackgroundResourceUrl, type: ResourceType.Image));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SectionType.Article:
|
||||||
|
ArticleDTO articleDTO = ArticleDTO.fromJson(rawSectionData)!;
|
||||||
|
var audioToDownload = articleDTO.audioIds!.firstWhere((a) => a.language == visitAppContext.language!);
|
||||||
|
if(audioToDownload.value != null) {
|
||||||
|
if(isConfigOffline)
|
||||||
|
{
|
||||||
|
// OFFLINE
|
||||||
|
List<Map<String, dynamic>> ressourceArticle = await DatabaseHelper.instance.queryWithColumnId(DatabaseTableType.resources, audioToDownload.value!);
|
||||||
|
if(ressourceArticle.isNotEmpty) {
|
||||||
|
resourcesModel.add(DatabaseHelper.instance.getResourceFromDB(ressourceArticle.first));
|
||||||
|
} else {
|
||||||
|
print("EMPTY resourcesModel - second");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ONLINE
|
||||||
|
ResourceDTO? resourceDTO = await client.resourceApi!.resourceGetDetail(audioToDownload.value!);
|
||||||
|
if(resourceDTO != null && resourceDTO.url != null) {
|
||||||
|
// ONLINE
|
||||||
|
//ResourceModel? resourceAudioOnline = await ApiService.downloadAudio(client, resourceDTO.url!, resourceDTO.id!);
|
||||||
|
ResourceModel resourceAudioOnline = ResourceModel();
|
||||||
|
resourceAudioOnline.id = resourceDTO.id;
|
||||||
|
resourceAudioOnline.source = resourceDTO.url;
|
||||||
|
resourceAudioOnline.type = ResourceType.Audio;
|
||||||
|
|
||||||
|
resourcesModel.add(resourceAudioOnline);
|
||||||
|
|
||||||
|
/*Uint8List base64String = base64Decode(resourceAudioOnline.path!); // GET FROM FILE
|
||||||
|
audiobytes = base64String;*/
|
||||||
|
} else {
|
||||||
|
print("EMPTY resourcesModel online - audio");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rawSectionData;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
print("IN CATCH");
|
print("IN CATCH");
|
||||||
|
|||||||
@ -40,12 +40,13 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<SectionDTO>?> getAllSections(Client client, String configurationId) async {
|
static Future<List<dynamic>?> getAllSections(Client client, String configurationId) async {
|
||||||
try {
|
try {
|
||||||
bool isOnline = await hasNetwork();
|
bool isOnline = await hasNetwork();
|
||||||
if(isOnline) {
|
if(isOnline) {
|
||||||
List<SectionDTO>? sections = await client.sectionApi!.sectionGetFromConfiguration(configurationId);
|
final rawList = await client.sectionApi!.sectionGetFromConfigurationDetail(configurationId);
|
||||||
return sections;
|
var sections = rawList.map((json) => SectionDTO.fromJson(json)).toList();
|
||||||
|
return rawList ?? [];
|
||||||
} else {
|
} else {
|
||||||
return []; // TODO return local list..
|
return []; // TODO return local list..
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
print("getAllSections IN CATCH");
|
print("getAllBeacons IN CATCH");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<File?> getResource(AppContext appContext, ConfigurationDTO configurationDTO, String imageId) async {
|
static Future<File?> getResource(AppContext appContext, ConfigurationDTO configurationDTO, String imageId) async {
|
||||||
if((appContext.getContext() as VisitAppContext).configuration == null || (appContext.getContext() as VisitAppContext).configuration!.isOffline!)
|
if(configurationDTO.isOffline!)
|
||||||
{
|
{
|
||||||
Directory? appDocumentsDirectory = Platform.isIOS ? await getApplicationDocumentsDirectory() : await getDownloadsDirectory();
|
Directory? appDocumentsDirectory = Platform.isIOS ? await getApplicationDocumentsDirectory() : await getDownloadsDirectory();
|
||||||
String localPath = appDocumentsDirectory!.path;
|
String localPath = appDocumentsDirectory!.path;
|
||||||
|
|||||||
@ -590,7 +590,7 @@ class SectionApi {
|
|||||||
/// Parameters:
|
/// Parameters:
|
||||||
///
|
///
|
||||||
/// * [String] id (required):
|
/// * [String] id (required):
|
||||||
Future<List<Object>?> sectionGetFromConfigurationDetail(
|
Future<dynamic> sectionGetFromConfigurationDetail(
|
||||||
String id,
|
String id,
|
||||||
) async {
|
) async {
|
||||||
final response = await sectionGetFromConfigurationDetailWithHttpInfo(
|
final response = await sectionGetFromConfigurationDetailWithHttpInfo(
|
||||||
@ -604,11 +604,13 @@ class SectionApi {
|
|||||||
// FormatException when trying to decode an empty string.
|
// FormatException when trying to decode an empty string.
|
||||||
if (response.body.isNotEmpty &&
|
if (response.body.isNotEmpty &&
|
||||||
response.statusCode != HttpStatus.noContent) {
|
response.statusCode != HttpStatus.noContent) {
|
||||||
final responseBody = await _decodeBodyBytes(response);
|
/*final responseBody = await _decodeBodyBytes(response);
|
||||||
return (await apiClient.deserializeAsync(responseBody, 'List<Object>')
|
return (await apiClient.deserializeAsync(responseBody, 'List<Object>')
|
||||||
as List)
|
as List)
|
||||||
.cast<Object>()
|
.cast<Object>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);*/
|
||||||
|
final decoded = json.decode(await _decodeBodyBytes(response));
|
||||||
|
return decoded; // <- Ce sera un Map<String, dynamic> ou une List<dynamic> selon le JSON
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user