mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 14:35:45 +00:00
Range filter
This commit is contained in:
parent
d3c6cf4b65
commit
025077bee7
3 changed files with 151 additions and 121 deletions
40
aidedejeu_flutter/lib/filterWidgets.dart
Normal file
40
aidedejeu_flutter/lib/filterWidgets.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import 'package:aidedejeu_flutter/models/items.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class RangeFilter extends StatefulWidget {
|
||||||
|
Filter filter;
|
||||||
|
|
||||||
|
RangeFilter({@required this.filter});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
// TODO: implement createState
|
||||||
|
return _RangeFilter(filter: filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RangeFilter extends State<RangeFilter> {
|
||||||
|
Filter filter;
|
||||||
|
RangeValues rangeValues;
|
||||||
|
_RangeFilter({@required this.filter}) {
|
||||||
|
rangeValues = RangeValues(0, filter.values.length.toDouble() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
return RangeSlider(
|
||||||
|
min: 0,
|
||||||
|
max: filter.values.length.toDouble() - 1,
|
||||||
|
divisions: filter.values.length,
|
||||||
|
labels: RangeLabels(
|
||||||
|
'${filter.values[rangeValues.start.round()]}', '${filter.values[rangeValues.end.round()]}'),
|
||||||
|
values: rangeValues ?? RangeValues(0, filter.values.length.toDouble() - 1),
|
||||||
|
onChanged: (RangeValues values) {
|
||||||
|
setState(() {
|
||||||
|
rangeValues = values;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:aidedejeu_flutter/database.dart';
|
import 'package:aidedejeu_flutter/database.dart';
|
||||||
|
import 'package:aidedejeu_flutter/filterWidgets.dart';
|
||||||
import 'package:aidedejeu_flutter/models/items.dart';
|
import 'package:aidedejeu_flutter/models/items.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
@ -160,6 +161,64 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Widget> buildFilterChipList(List<String> choices) {
|
||||||
|
return choices
|
||||||
|
.map((choice) => Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: FilterChip(
|
||||||
|
label: Text(choice),
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
shape: StadiumBorder(side: BorderSide()),
|
||||||
|
onSelected: (bool value) {
|
||||||
|
print("selected");
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildChoiceFilter(Filter filter) {
|
||||||
|
return Wrap(children: buildFilterChipList(filter.values));
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildRangeFilter(Filter filter) {
|
||||||
|
/*return RangeSlider(
|
||||||
|
min: 0,
|
||||||
|
max: 1.0 * filter.values.length,
|
||||||
|
divisions: filter.values.length,
|
||||||
|
labels: RangeLabels(
|
||||||
|
'début ${filter.values.first}', 'fin ${filter.values.last}'),
|
||||||
|
values: RangeValues(0, 1.0 * filter.values.length),
|
||||||
|
onChanged: (RangeValues value) {});*/
|
||||||
|
return RangeFilter(filter: filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildFilter(Filter filter) {
|
||||||
|
return Column(children: <Widget>[
|
||||||
|
Divider(
|
||||||
|
color: Colors.blueGrey,
|
||||||
|
height: 10.0,
|
||||||
|
),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(filter.name),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
child: filter.type == FilterType.Choices
|
||||||
|
? buildChoiceFilter(filter)
|
||||||
|
: buildRangeFilter(filter))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> buildFilterList() {
|
||||||
|
return (item as FilteredItems)
|
||||||
|
.toFilterList()
|
||||||
|
.map((filter) => buildFilter(filter))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
int indexPage = 0;
|
int indexPage = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -191,110 +250,33 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
},
|
},
|
||||||
items: buildBottomNavigationBarItems(),
|
items: buildBottomNavigationBarItems(),
|
||||||
),
|
),
|
||||||
endDrawer: item is FilteredItems ? Drawer(
|
endDrawer: item is FilteredItems
|
||||||
child: ListView(
|
? Drawer(
|
||||||
// Important: Remove any padding from the ListView.
|
child: ListView(
|
||||||
padding: EdgeInsets.zero,
|
// Important: Remove any padding from the ListView.
|
||||||
children: (item as FilteredItems).toFilterMap().entries.map(
|
padding: EdgeInsets.zero,
|
||||||
(filter) =>
|
children: buildFilterList()),
|
||||||
//ListTile(title: Text(filter.key))
|
|
||||||
Container(
|
|
||||||
child: Wrap(
|
|
||||||
children: filter.value.toString().split("|").map(
|
|
||||||
(choice) =>
|
|
||||||
FilterChip(
|
|
||||||
label: Text(choice),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
shape: StadiumBorder(side: BorderSide()),
|
|
||||||
onSelected: (bool value) {
|
|
||||||
print("selected");
|
|
||||||
},
|
|
||||||
)
|
|
||||||
).toList()/* <Widget>[
|
|
||||||
FilterChip(
|
|
||||||
label: Text("truc"),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
shape: StadiumBorder(side: BorderSide()),
|
|
||||||
onSelected: (bool value) {
|
|
||||||
print("selected");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
FilterChip(
|
|
||||||
label: Text("truc"),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
shape: StadiumBorder(side: BorderSide()),
|
|
||||||
onSelected: (bool value) {
|
|
||||||
print("selected");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],*/
|
|
||||||
),
|
|
||||||
|
|
||||||
)
|
)
|
||||||
).toList()
|
: null,
|
||||||
/*<Widget>[
|
|
||||||
|
|
||||||
DrawerHeader(
|
|
||||||
child: Text('Drawer Header'),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
title: Text('Item 1'),
|
|
||||||
onTap: () {
|
|
||||||
// Update the state of the app.
|
|
||||||
// ...
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
title: Text('Item 2'),
|
|
||||||
onTap: () {
|
|
||||||
// Update the state of the app.
|
|
||||||
// ...
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
child: Wrap(
|
|
||||||
children: <Widget>[
|
|
||||||
FilterChip(
|
|
||||||
label: Text("truc"),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
shape: StadiumBorder(side: BorderSide()),
|
|
||||||
onSelected: (bool value) {
|
|
||||||
print("selected");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
FilterChip(
|
|
||||||
label: Text("truc"),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
shape: StadiumBorder(side: BorderSide()),
|
|
||||||
onSelected: (bool value) {
|
|
||||||
print("selected");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],*/
|
|
||||||
),
|
|
||||||
) : null,
|
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.id),
|
title: Text(widget.id),
|
||||||
actions: item is FilteredItems ? [
|
actions: item is FilteredItems
|
||||||
Builder(
|
? [
|
||||||
builder: (context) => IconButton(
|
Builder(
|
||||||
icon: SvgPicture.asset(
|
builder: (context) => IconButton(
|
||||||
"assets/funnel.svg",
|
icon: SvgPicture.asset(
|
||||||
height: 30.0,
|
"assets/funnel.svg",
|
||||||
width: 30.0,
|
height: 30.0,
|
||||||
allowDrawingOutsideViewBox: true,
|
width: 30.0,
|
||||||
), //Icon(Icons.filter),
|
allowDrawingOutsideViewBox: true,
|
||||||
onPressed: () => Scaffold.of(context).openEndDrawer(),
|
), //Icon(Icons.filter),
|
||||||
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
|
onPressed: () => Scaffold.of(context).openEndDrawer(),
|
||||||
),
|
tooltip:
|
||||||
),
|
MaterialLocalizations.of(context).openAppDrawerTooltip,
|
||||||
] : null,
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class Items extends Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FilteredItems extends Items {
|
abstract class FilteredItems extends Items {
|
||||||
String Family;
|
String Family;
|
||||||
|
|
||||||
FilteredItems.fromMap(Map<String, dynamic> map)
|
FilteredItems.fromMap(Map<String, dynamic> map)
|
||||||
|
|
@ -117,36 +117,44 @@ class FilteredItems extends Items {
|
||||||
this.Family = map["Family"];
|
this.Family = map["Family"];
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toFilterMap() {
|
List<Filter> toFilterList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
enum FilterType {
|
||||||
|
Choices, Range
|
||||||
|
}
|
||||||
|
class Filter {
|
||||||
|
String name;
|
||||||
|
FilterType type;
|
||||||
|
List<String> values;
|
||||||
|
Filter({this.name, this.type, this.values});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonsterItems extends FilteredItems {
|
class MonsterItems extends FilteredItems {
|
||||||
String Types;
|
Filter types;
|
||||||
String Challenges;
|
Filter challenges;
|
||||||
String Sizes;
|
Filter sizes;
|
||||||
String Sources;
|
Filter sources;
|
||||||
String Terrains;
|
Filter terrains;
|
||||||
|
|
||||||
MonsterItems.fromMap(Map<String, dynamic> map)
|
MonsterItems.fromMap(Map<String, dynamic> map)
|
||||||
: super.fromMap(map) {
|
: super.fromMap(map) {
|
||||||
this.Types = map["Types"];
|
this.types = Filter(name: "Type", type: FilterType.Choices, values: map["Types"].toString().split("|"));
|
||||||
this.Challenges = map["Challenges"];
|
this.challenges = Filter(name: "Dangerosité", type: FilterType.Range, values: map["Challenges"].toString().split("|"));
|
||||||
this.Sizes = map["Sizes"];
|
this.sizes = Filter(name: "Taille", type: FilterType.Range, values: map["Sizes"].toString().split("|"));;
|
||||||
this.Sources = map["Sources"];
|
this.sources = Filter(name: "Source", type: FilterType.Choices, values: map["Sources"].toString().split("|"));
|
||||||
this.Terrains = map["Terrains"];
|
this.terrains = Filter(name: "Terrain", type: FilterType.Choices, values: map["Terrains"].toString().split("|"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map<String, dynamic> toMap() => {
|
// Map<String, dynamic> toMap() => {
|
||||||
//"Id": Id,
|
//"Id": Id,
|
||||||
Map<String, dynamic> toFilterMap() => {
|
List<Filter> toFilterList() => {
|
||||||
"Types": Types,
|
types,
|
||||||
"Challenges": Challenges,
|
challenges,
|
||||||
"Sizes": Sizes,
|
sizes,
|
||||||
"Sources": Sources,
|
sources,
|
||||||
"Terrains": Terrains,
|
terrains,
|
||||||
};
|
}.toList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue