240 lines
9.4 KiB
Dart
240 lines
9.4 KiB
Dart
import 'package:diacritic/diacritic.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:mymuseum_visitapp/Components/loading_common.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/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/Services/apiService.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
import 'package:mymuseum_visitapp/constants.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'section_card.dart';
|
|
|
|
class Body extends StatefulWidget {
|
|
const Body({Key? key, required this.configuration}) : super(key: key);
|
|
|
|
final ConfigurationDTO configuration;
|
|
|
|
@override
|
|
State<Body> createState() => _BodyState();
|
|
}
|
|
|
|
class _BodyState extends State<Body> {
|
|
List<SectionDTO> sections = [];
|
|
List<SectionDTO> sectionsToDisplay = [];
|
|
String? searchValue;
|
|
int? searchNumberValue;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
VisitAppContext visitAppContext = appContext.getContext();
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return SafeArea(
|
|
bottom: false,
|
|
top: false,
|
|
child: Stack(
|
|
children: [
|
|
Hero(
|
|
tag: widget.configuration.id!,
|
|
child: Container(
|
|
height: size.height * 0.28,
|
|
decoration: BoxDecoration(
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: kMainGrey,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 5,
|
|
offset: Offset(0, 1), // changes position of shadow
|
|
),
|
|
],
|
|
image: widget.configuration.imageSource != null ? DecorationImage(
|
|
fit: BoxFit.cover,
|
|
opacity: 0.65,
|
|
image: NetworkImage(
|
|
widget.configuration.imageSource!,
|
|
),
|
|
): null,
|
|
),
|
|
),
|
|
),
|
|
Column(
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: size.height * 0.11,
|
|
width: size.width,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Positioned(
|
|
top: 35,
|
|
left: 10,
|
|
child: SizedBox(
|
|
width: 50,
|
|
height: 50,
|
|
child: InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
visitAppContext.configuration = null;
|
|
visitAppContext.isScanningBeacons = false;
|
|
Navigator.of(context).pop();
|
|
/*Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
|
|
builder: (context) => const HomePage3(),
|
|
),(route) => false);*/
|
|
});
|
|
},
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
color: kMainColor,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(Icons.chevron_left, size: 28, color: Colors.white)
|
|
),
|
|
)
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Row(
|
|
children: [
|
|
SearchBox(onChanged: (value) {
|
|
setState(() {
|
|
if(value != null && value != "") {
|
|
searchValue = value;
|
|
} else {
|
|
searchValue = null;
|
|
}
|
|
});
|
|
}),
|
|
Expanded(
|
|
child: SearchNumberBox(onChanged: (value) {
|
|
setState(() {
|
|
if(value != null && value != "") {
|
|
searchNumberValue = int.parse(value);
|
|
} else {
|
|
searchNumberValue = null;
|
|
FocusScope.of(context).unfocus();
|
|
}
|
|
});
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
//const SizedBox(height: kDefaultPadding / 2),
|
|
Expanded(
|
|
child: Stack(
|
|
children: <Widget>[
|
|
// Our background
|
|
Container(
|
|
margin: const EdgeInsets.only(top: 0),
|
|
decoration: const BoxDecoration(
|
|
color: kBackgroundColor,
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(40),
|
|
topRight: Radius.circular(40),
|
|
),
|
|
),
|
|
),
|
|
FutureBuilder(
|
|
future: getSections(appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
/*print("SECTIONTODISPA");
|
|
print(sectionsToDisplay);*/
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 0),
|
|
child: RefreshIndicator(
|
|
onRefresh: () async {
|
|
if(!widget.configuration.isOffline!) {
|
|
// Force refresh if online
|
|
setState(() {});
|
|
} },
|
|
child: ListView.builder(
|
|
itemCount: sectionsToDisplay.length,
|
|
itemBuilder: (context, index) => SectionCard(
|
|
itemCount: sectionsToDisplay.length,
|
|
itemIndex: index,
|
|
sectionDTO: sectionsToDisplay[index],
|
|
press: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => SectionPage(
|
|
visitAppContextIn: appContext.getContext(),
|
|
sectionId: sectionsToDisplay[index].id!,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return Text(TranslationHelper.getFromLocale("noData", appContext.getContext()));
|
|
} else {
|
|
return Center(
|
|
child: SizedBox(
|
|
height: size.height * 0.15,
|
|
child: const LoadingCommon()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getSections(AppContext appContext) async {
|
|
VisitAppContext visitAppContext = appContext.getContext();
|
|
if(widget.configuration.isOffline!)
|
|
{
|
|
// OFFLINE
|
|
sections = List<SectionDTO>.from(await DatabaseHelper.instance.getData(DatabaseTableType.sections));
|
|
}
|
|
else
|
|
{
|
|
// ONLINE
|
|
List<SectionDTO>? sectionsDownloaded = await ApiService.getAllSections(visitAppContext.clientAPI, widget.configuration.id!);
|
|
//print(sectionsDownloaded);
|
|
if(sectionsDownloaded!.isNotEmpty) {
|
|
sections = sectionsDownloaded.toList();
|
|
//print(sections);
|
|
}
|
|
}
|
|
|
|
sections = sections.where((s) => s.configurationId == widget.configuration.id!).toList();
|
|
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
|
sectionsToDisplay = sections;
|
|
|
|
visitAppContext.currentSections = sectionsToDisplay;
|
|
|
|
if(searchValue != '' && searchValue != null) {
|
|
sectionsToDisplay = sections.where((s) => removeDiacritics(TranslationHelper.get(s.title, appContext.getContext()).toLowerCase()).contains(removeDiacritics(searchValue.toString().toLowerCase()))).toList();
|
|
} else {
|
|
if(searchNumberValue != null) {
|
|
sectionsToDisplay = sections.where((s) => s.order!+1 == searchNumberValue).toList();
|
|
} else {
|
|
sectionsToDisplay = sections;
|
|
}
|
|
}
|
|
}
|
|
}
|