Put table in a expandable view
This commit is contained in:
parent
77c595528c
commit
7639eb7bc0
2 changed files with 44 additions and 19 deletions
|
@ -68,7 +68,8 @@ class CategoryWidget extends StatelessWidget {
|
||||||
|
|
||||||
CategoryWidget({super.key, required this.category});
|
CategoryWidget({super.key, required this.category});
|
||||||
|
|
||||||
String capitalize(String s) {
|
String Name() {
|
||||||
|
var s = category.name;
|
||||||
return "${s[0].toUpperCase()}${s.substring(1)}";
|
return "${s[0].toUpperCase()}${s.substring(1)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,16 +115,10 @@ class CategoryWidget extends StatelessWidget {
|
||||||
"Power Draw"),
|
"Power Draw"),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
return Table(
|
||||||
Text(
|
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
textScaleFactor: 2.0,
|
|
||||||
capitalize(category.name)),
|
|
||||||
Table(
|
|
||||||
border: TableBorder.all(),
|
border: TableBorder.all(),
|
||||||
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
||||||
children: list)
|
children: list);
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ class MyHomePage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
List<bool> expanded = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<List<Category>>(
|
return FutureBuilder<List<Category>>(
|
||||||
|
@ -42,19 +44,47 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
return const Text("still loading");
|
return const Text("still loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final data = categories.data!;
|
||||||
|
final category_count = data.length;
|
||||||
|
|
||||||
|
if (category_count > expanded.length) {
|
||||||
|
final int diff = category_count - expanded.length;
|
||||||
|
|
||||||
|
final List<bool> diff_list = List<bool>.filled(diff, true);
|
||||||
|
expanded.addAll(diff_list);
|
||||||
|
} else if (category_count < expanded.length) {
|
||||||
|
final int diff = expanded.length - category_count;
|
||||||
|
|
||||||
|
expanded = List<bool>.filled(diff, false);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Column(children: [
|
||||||
child: Column(
|
ExpansionPanelList(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
expansionCallback: (int index, bool isExpanded) {
|
||||||
children: categories.data!
|
setState(() {
|
||||||
.map((category) => CategoryWidget(category: category))
|
expanded[index] = isExpanded;
|
||||||
.toList(),
|
});
|
||||||
),
|
},
|
||||||
));
|
children: data.asMap().entries.map(
|
||||||
|
(category) {
|
||||||
|
final CategoryWidget widget =
|
||||||
|
CategoryWidget(category: category.value);
|
||||||
|
|
||||||
|
return ExpansionPanel(
|
||||||
|
headerBuilder:
|
||||||
|
(BuildContext context, bool isExpanded) {
|
||||||
|
return ListTile(title: Text(widget.Name()));
|
||||||
|
},
|
||||||
|
body: widget,
|
||||||
|
isExpanded: expanded[category.key]);
|
||||||
|
},
|
||||||
|
).toList())
|
||||||
|
]));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue