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/filterWidgets.dart';
|
||||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:flutter/material.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;
|
||||
|
||||
@override
|
||||
|
|
@ -191,97 +250,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
},
|
||||
items: buildBottomNavigationBarItems(),
|
||||
),
|
||||
endDrawer: item is FilteredItems ? Drawer(
|
||||
endDrawer: item is FilteredItems
|
||||
? Drawer(
|
||||
child: ListView(
|
||||
// Important: Remove any padding from the ListView.
|
||||
padding: EdgeInsets.zero,
|
||||
children: (item as FilteredItems).toFilterMap().entries.map(
|
||||
(filter) =>
|
||||
//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");
|
||||
},
|
||||
children: buildFilterList()),
|
||||
)
|
||||
).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()
|
||||
/*<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,
|
||||
: null,
|
||||
appBar: AppBar(
|
||||
title: Text(widget.id),
|
||||
actions: item is FilteredItems ? [
|
||||
actions: item is FilteredItems
|
||||
? [
|
||||
Builder(
|
||||
builder: (context) => IconButton(
|
||||
icon: SvgPicture.asset(
|
||||
|
|
@ -291,10 +271,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
allowDrawingOutsideViewBox: true,
|
||||
), //Icon(Icons.filter),
|
||||
onPressed: () => Scaffold.of(context).openEndDrawer(),
|
||||
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
|
||||
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;
|
||||
|
||||
FilteredItems.fromMap(Map<String, dynamic> map)
|
||||
|
|
@ -117,36 +117,44 @@ class FilteredItems extends Items {
|
|||
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 {
|
||||
String Types;
|
||||
String Challenges;
|
||||
String Sizes;
|
||||
String Sources;
|
||||
String Terrains;
|
||||
Filter types;
|
||||
Filter challenges;
|
||||
Filter sizes;
|
||||
Filter sources;
|
||||
Filter terrains;
|
||||
|
||||
MonsterItems.fromMap(Map<String, dynamic> map)
|
||||
: super.fromMap(map) {
|
||||
this.Types = map["Types"];
|
||||
this.Challenges = map["Challenges"];
|
||||
this.Sizes = map["Sizes"];
|
||||
this.Sources = map["Sources"];
|
||||
this.Terrains = map["Terrains"];
|
||||
this.types = Filter(name: "Type", type: FilterType.Choices, values: map["Types"].toString().split("|"));
|
||||
this.challenges = Filter(name: "Dangerosité", type: FilterType.Range, values: map["Challenges"].toString().split("|"));
|
||||
this.sizes = Filter(name: "Taille", type: FilterType.Range, values: map["Sizes"].toString().split("|"));;
|
||||
this.sources = Filter(name: "Source", type: FilterType.Choices, values: map["Sources"].toString().split("|"));
|
||||
this.terrains = Filter(name: "Terrain", type: FilterType.Choices, values: map["Terrains"].toString().split("|"));
|
||||
}
|
||||
|
||||
// Map<String, dynamic> toMap() => {
|
||||
//"Id": Id,
|
||||
Map<String, dynamic> toFilterMap() => {
|
||||
"Types": Types,
|
||||
"Challenges": Challenges,
|
||||
"Sizes": Sizes,
|
||||
"Sources": Sources,
|
||||
"Terrains": Terrains,
|
||||
};
|
||||
List<Filter> toFilterList() => {
|
||||
types,
|
||||
challenges,
|
||||
sizes,
|
||||
sources,
|
||||
terrains,
|
||||
}.toList();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue