141 lines
5.1 KiB
Dart
141 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_api/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/Screens/Article/article.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.configurationId}) : super(key: key);
|
|
|
|
final String? configurationId;
|
|
|
|
@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);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return SafeArea(
|
|
bottom: false,
|
|
child: Column(
|
|
children: <Widget>[
|
|
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) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 0),
|
|
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) => ArticlePage(
|
|
articleId: sectionsToDisplay[index].id!,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return Text(TranslationHelper.getFromLocale("noData", appContext));
|
|
} else {
|
|
return Center(
|
|
child: Container(
|
|
height: size.height * 0.15,
|
|
child: Loading()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getSections(AppContext appContext) async {
|
|
sections = List<SectionDTO>.from(await DatabaseHelper.instance.getData(DatabaseTableType.sections));
|
|
sections = sections.where((s) => s.configurationId == widget.configurationId).toList();
|
|
sections.sort((a,b) => a.order!.compareTo(b.order!));
|
|
sectionsToDisplay = sections;
|
|
|
|
if(searchValue != '' && searchValue != null) {
|
|
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();
|
|
} else {
|
|
sectionsToDisplay = sections;
|
|
}
|
|
}
|
|
}
|
|
}
|