update flow pages
This commit is contained in:
parent
df69e56d95
commit
37757ee445
3 changed files with 169 additions and 25 deletions
|
@ -490,3 +490,8 @@ class GlobalItemStat {
|
||||||
total_price = json["total_price"];
|
total_price = json["total_price"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(String, String) itemVariant(String iv) {
|
||||||
|
var split = iv.split("::");
|
||||||
|
return (split[0], split[1]);
|
||||||
|
}
|
||||||
|
|
52
lib/pages/expandable_list.dart
Normal file
52
lib/pages/expandable_list.dart
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class ExpandableListItem {
|
||||||
|
ExpandableListItem({
|
||||||
|
required this.body,
|
||||||
|
required this.header,
|
||||||
|
this.isExpanded = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
Widget body;
|
||||||
|
Widget header;
|
||||||
|
bool isExpanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExpandableList extends StatefulWidget {
|
||||||
|
final List<ExpandableListItem> entries;
|
||||||
|
|
||||||
|
const ExpandableList(this.entries, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ExpandableList> createState() => _ExpandableListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExpandableListState extends State<ExpandableList> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: Container(
|
||||||
|
child: _buildPanel(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildPanel() {
|
||||||
|
return ExpansionPanelList(
|
||||||
|
expansionCallback: (int index, bool isExpanded) {
|
||||||
|
setState(() {
|
||||||
|
widget.entries[index].isExpanded = isExpanded;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
children: widget.entries.map<ExpansionPanel>((ExpandableListItem item) {
|
||||||
|
return ExpansionPanel(
|
||||||
|
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||||
|
return item.header;
|
||||||
|
},
|
||||||
|
body: item.body,
|
||||||
|
isExpanded: item.isExpanded,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,49 +1,136 @@
|
||||||
import 'package:cdb_ui/api.dart' as API;
|
import 'package:cdb_ui/api.dart' as API;
|
||||||
|
import 'package:cdb_ui/pages/expandable_list.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class FlowsPage extends StatelessWidget {
|
class FlowsPage extends StatefulWidget {
|
||||||
const FlowsPage({super.key});
|
const FlowsPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FlowsPage> createState() => _FlowsPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FlowsPageState extends State<FlowsPage> {
|
||||||
|
int tabSelection = 0;
|
||||||
|
Map<String, API.FlowInfo>? flowInfos;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
API.API().getFlows().then(
|
||||||
|
(value) {
|
||||||
|
setState(() {
|
||||||
|
flowInfos = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget flowTile(BuildContext context, API.FlowInfo x) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(x.name),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (context) => FlowInfoPage(x),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget listAllFlowInfos(
|
Widget listAllFlowInfos(
|
||||||
BuildContext context, Map<String, API.FlowInfo> infos) {
|
BuildContext context, Map<String, API.FlowInfo> infos) {
|
||||||
return ListView(
|
return ListView(
|
||||||
children: infos.values.map((x) {
|
children: infos.values.map((x) {
|
||||||
return ListTile(
|
return flowTile(context, x);
|
||||||
title: Text(x.name),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(
|
|
||||||
builder: (context) => FlowPage(x),
|
|
||||||
));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}).toList());
|
}).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget listFlowInfoByProduced(
|
||||||
|
BuildContext context, Map<String, API.FlowInfo> infos) {
|
||||||
|
Map<String, List<API.FlowInfo>> producedMapping = {};
|
||||||
|
|
||||||
|
for (var f in infos.values) {
|
||||||
|
for (var produces in f.produces ?? []) {
|
||||||
|
var item = API.itemVariant(produces).$1;
|
||||||
|
producedMapping.putIfAbsent(item, () {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
producedMapping[item]!.add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ExpandableListItem> items = [];
|
||||||
|
|
||||||
|
for (var key in producedMapping.keys) {
|
||||||
|
var flows = Column(
|
||||||
|
children: producedMapping[key]!.map((x) {
|
||||||
|
return flowTile(context, x);
|
||||||
|
}).toList());
|
||||||
|
items.add(ExpandableListItem(body: flows, header: Text(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExpandableList(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget listFlowInfoByDependant(
|
||||||
|
BuildContext context, Map<String, API.FlowInfo> infos) {
|
||||||
|
Map<String, List<API.FlowInfo>> dependsMapping = {};
|
||||||
|
|
||||||
|
for (var f in infos.values) {
|
||||||
|
for (var produces in f.depends) {
|
||||||
|
var item = API.itemVariant(produces).$1;
|
||||||
|
// todo : add only if item is in inventory
|
||||||
|
dependsMapping.putIfAbsent(item, () {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
dependsMapping[item]!.add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ExpandableListItem> items = [];
|
||||||
|
|
||||||
|
for (var key in dependsMapping.keys) {
|
||||||
|
var flows = Column(
|
||||||
|
children: dependsMapping[key]!.map((x) {
|
||||||
|
return flowTile(context, x);
|
||||||
|
}).toList());
|
||||||
|
items.add(ExpandableListItem(body: flows, header: Text(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExpandableList(items);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// todo : flows (info) by item produced
|
|
||||||
// todo : list currently active
|
// todo : list currently active
|
||||||
// todo : flows by item needed (show only avail)
|
|
||||||
|
if (flowInfos == null) {
|
||||||
|
return const CircularProgressIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text("Flows")),
|
appBar: AppBar(
|
||||||
body: FutureBuilder(
|
title: const Text("Flows"),
|
||||||
future: API.API().getFlows(),
|
bottom: TabBar(
|
||||||
builder: (ctx, snap) {
|
tabs: const [Text("All"), Text("Produces"), Text("Depends")],
|
||||||
if (!snap.hasData) {
|
onTap: (value) {
|
||||||
return const CircularProgressIndicator();
|
setState(() {
|
||||||
}
|
tabSelection = value;
|
||||||
|
});
|
||||||
var data = snap.data!;
|
},
|
||||||
|
)),
|
||||||
return listAllFlowInfos(context, data);
|
body: switch (tabSelection) {
|
||||||
}));
|
0 => listAllFlowInfos(context, flowInfos!),
|
||||||
|
1 => listFlowInfoByProduced(context, flowInfos!),
|
||||||
|
2 => listFlowInfoByDependant(context, flowInfos!),
|
||||||
|
_ => const Text("..."),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FlowPage extends StatelessWidget {
|
class FlowInfoPage extends StatelessWidget {
|
||||||
final API.FlowInfo info;
|
final API.FlowInfo info;
|
||||||
|
|
||||||
const FlowPage(this.info, {super.key});
|
const FlowInfoPage(this.info, {super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
Loading…
Reference in a new issue