284 lines
9.1 KiB
Dart
284 lines
9.1 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hiddingsel_app/appflow/controller/articles.dart';
|
|
import 'package:hiddingsel_app/appflow/model/companies.dart' as enu;
|
|
import 'package:hiddingsel_app/appflow/view/further_pages/article.dart';
|
|
import 'package:hiddingsel_app/constants/constant.dart';
|
|
import 'package:hiddingsel_app/appflow/model/represented_organisations.dart' as enu2;
|
|
import 'package:hiddingsel_app/appflow/model/articles.dart';
|
|
import 'package:hiddingsel_app/appflow/view/menu_pages/companies.dart';
|
|
import 'package:hiddingsel_app/appflow/view/menu_pages/organisations.dart';
|
|
import 'package:hiddingsel_app/appflow/view/menu_pages/das_dorf.dart';
|
|
import 'package:hiddingsel_app/appflow/view/menu_pages/pois.dart';
|
|
|
|
import '../../model/pois.dart';
|
|
import '../home.dart';
|
|
import 'article_list.dart';
|
|
import '../navigation_drawer.dart';
|
|
|
|
class Search extends StatelessWidget with NavigationDrawerItem {
|
|
|
|
String get title => 'Suche';
|
|
final Function(PreferredSizeWidget appBar, Widget body) _onChange;
|
|
|
|
const Search(this._onChange);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
TextEditingController controller = new TextEditingController();
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
if (controller.value.text.isEmpty) {
|
|
return buildSearch(controller, setState, context);
|
|
} else {
|
|
return buildResults(controller, setState, context);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget buildSearch(
|
|
TextEditingController controller, setState, BuildContext context) =>
|
|
LayoutBuilder(
|
|
builder: (context, constraints) => Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(gradient: UIGradiants.red),
|
|
width: constraints.maxWidth,
|
|
height: constraints.maxHeight,
|
|
),
|
|
Positioned(
|
|
top: constraints.maxHeight * 0.6,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
width: constraints.maxWidth * 0.8,
|
|
height: UIShapes.paddingMax,
|
|
child: TextField(
|
|
onSubmitted: (s) {
|
|
setState(() {
|
|
controller = controller;
|
|
});
|
|
},
|
|
textInputAction: TextInputAction.search,
|
|
controller: controller,
|
|
autofocus: true,
|
|
decoration: InputDecoration(
|
|
border: InputBorder.none,
|
|
hintText: 'SUCHEN',
|
|
hintStyle: UITheme.theme.textTheme.displayMedium?.apply(
|
|
color: UIColors.white.withAlpha(100),
|
|
),
|
|
),
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: UIColors.white,
|
|
fontSize: UIShapes.paddingMax,
|
|
),
|
|
),
|
|
),
|
|
Divider(),
|
|
FloatingActionButton(
|
|
backgroundColor: UIColors.white,
|
|
child: Icon(
|
|
Icons.search,
|
|
color: UIColors.grey5,
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
controller = controller;
|
|
});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
Widget buildResults(
|
|
TextEditingController controller, setState, BuildContext context) {
|
|
String searchWord = controller.value.text;
|
|
|
|
List<enu2.RepresentedOrganisationModel> orgas = enu2.RepresentedOrganisationModel.values
|
|
.where((element) =>
|
|
element.tags.any((alias) => alias.toLowerCase().contains(searchWord.toLowerCase())))
|
|
.toList();
|
|
List<enu.CompanyModel> comps = enu.CompanyModel.values
|
|
.where((element) =>
|
|
element.name.toLowerCase().contains(searchWord.toLowerCase()))
|
|
.toList();
|
|
List<PointOfInterestModel> pois = PointOfInterestModel.values
|
|
.where((element) =>
|
|
element.name.toLowerCase().contains(searchWord.toLowerCase()))
|
|
.toList();
|
|
List others = ['Vorwort', 'Geschichte']
|
|
.where((element) =>
|
|
element.toLowerCase().contains(searchWord.toLowerCase()))
|
|
.toList();
|
|
|
|
List<Widget> children = [];
|
|
if (orgas.isNotEmpty) {
|
|
children.addAll([
|
|
Text(
|
|
OrganisationListView(null).title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.headlineMedium,
|
|
),
|
|
Divider(),
|
|
]);
|
|
for (enu2.RepresentedOrganisationModel o in orgas) {
|
|
children.addAll([
|
|
GestureDetector(
|
|
child: Text(
|
|
'... ' + o.name.toUpperCase(),
|
|
style: UITheme.theme.textTheme.titleLarge,
|
|
),
|
|
onTap: () {
|
|
Home.openPage(OrganisationPagesView(o, _onChange), _onChange);
|
|
},
|
|
),
|
|
Divider()
|
|
]);
|
|
}
|
|
}
|
|
if (comps.isNotEmpty) {
|
|
children.addAll([
|
|
Text(
|
|
CompanyListView(null).title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.headlineMedium,
|
|
),
|
|
Divider(),
|
|
]);
|
|
for (enu.CompanyModel o in comps) {
|
|
children.addAll([
|
|
GestureDetector(
|
|
child: Text(
|
|
'... ' + o.name.toUpperCase(),
|
|
style: UITheme.theme.textTheme.titleLarge,
|
|
),
|
|
onTap: () {
|
|
Home.openPage(CompanyPagesView(o), _onChange);
|
|
},
|
|
),
|
|
Divider()
|
|
]);
|
|
}
|
|
}
|
|
if (pois.isNotEmpty) {
|
|
children.addAll([
|
|
Text(
|
|
PoiListView(null).title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.headlineMedium,
|
|
),
|
|
Divider(),
|
|
]);
|
|
for (PointOfInterestModel o in pois) {
|
|
children.addAll([
|
|
GestureDetector(
|
|
child: Text(
|
|
'... ' + o.name.toUpperCase(),
|
|
style: UITheme.theme.textTheme.titleLarge,
|
|
),
|
|
onTap: () {
|
|
Home.openPage(PoiPagesView(o), _onChange);
|
|
},
|
|
),
|
|
Divider()
|
|
]);
|
|
}
|
|
}
|
|
if (others.isNotEmpty) {
|
|
children.addAll([
|
|
Text(
|
|
DasDorfListView(null).title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.headlineMedium,
|
|
),
|
|
Divider(),
|
|
]);
|
|
for (String o in others) {
|
|
children.addAll([
|
|
GestureDetector(
|
|
child: Text(
|
|
'... ' + o.toUpperCase(),
|
|
style: UITheme.theme.textTheme.titleLarge,
|
|
),
|
|
onTap: () {
|
|
Home.openPage(DasDorfListView(_onChange), _onChange);
|
|
},
|
|
),
|
|
Divider()
|
|
]);
|
|
}
|
|
}
|
|
|
|
return FutureBuilder(
|
|
future: ArticleController.getSearchResultListStream(
|
|
searchWord).first,
|
|
builder: (context, AsyncSnapshot snapshot) {
|
|
if (snapshot.data != null) {
|
|
List<ArticleModel> arts = snapshot.data;
|
|
if (arts.isNotEmpty) {
|
|
List<Widget> news = [
|
|
Text(
|
|
ArticleListView(null).title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.headlineMedium,
|
|
),
|
|
Divider(),
|
|
];
|
|
for (ArticleModel o in arts) {
|
|
news.addAll([
|
|
GestureDetector(
|
|
child: Text(
|
|
'... ' + o.title.toUpperCase(),
|
|
style: UITheme.theme.textTheme.titleLarge,
|
|
),
|
|
onTap: () {
|
|
Home.openPage(ArticleView(o), _onChange);
|
|
},
|
|
),
|
|
Divider(),
|
|
]);
|
|
}
|
|
news.addAll(children);
|
|
children = news;
|
|
}
|
|
}
|
|
|
|
return Container(
|
|
padding: EdgeInsets.all(UIShapes.paddingMax),
|
|
decoration: BoxDecoration(gradient: UIGradiants.red),
|
|
child: ListView(
|
|
children: [
|
|
SizedBox(
|
|
height: UIShapes.paddingMax,
|
|
child: Text(searchWord.toUpperCase(),
|
|
textAlign: TextAlign.center,
|
|
style: UITheme.theme.textTheme.displayMedium),
|
|
),
|
|
Divider(),
|
|
FloatingActionButton(
|
|
backgroundColor: UIColors.white,
|
|
child: Icon(
|
|
Icons.cancel_outlined,
|
|
color: UIColors.grey5,
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
controller.clear();
|
|
});
|
|
},
|
|
),
|
|
Divider(),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: children,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|