mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
Add collapse button to the address book (#357)
* Added collapsible list to the Address Book * fix text style
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import 'package:cake_wallet/src/widgets/standard_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CollapsibleSectionList extends SectionStandardList {
|
||||
CollapsibleSectionList(
|
||||
{bool hasTopSeparator,
|
||||
BuildContext context,
|
||||
int sectionCount,
|
||||
int Function(int sectionIndex) itemCounter,
|
||||
Widget Function(BuildContext context, int sectionIndex, int itemIndex)
|
||||
itemBuilder,
|
||||
Widget Function(BuildContext context, int sectionIndex)
|
||||
sectionTitleBuilder,
|
||||
Color themeColor,
|
||||
Color dividerThemeColor})
|
||||
: super(
|
||||
hasTopSeparator: hasTopSeparator,
|
||||
sectionCount: sectionCount,
|
||||
itemCounter: itemCounter,
|
||||
itemBuilder: itemBuilder,
|
||||
sectionTitleBuilder: sectionTitleBuilder,
|
||||
themeColor: themeColor,
|
||||
dividerThemeColor: dividerThemeColor);
|
||||
|
||||
@override
|
||||
List<Widget> transform(
|
||||
bool hasTopSeparator,
|
||||
BuildContext context,
|
||||
int sectionCount,
|
||||
int Function(int sectionIndex) itemCounter,
|
||||
Widget Function(BuildContext context, int sectionIndex, int itemIndex)
|
||||
itemBuilder,
|
||||
Widget Function(BuildContext context, int sectionIndex)
|
||||
sectionTitleBuilder,
|
||||
themeColor,
|
||||
dividerThemeColor) {
|
||||
final items = <Widget>[];
|
||||
|
||||
for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) {
|
||||
final itemCount = itemCounter(sectionIndex);
|
||||
|
||||
items.add(Theme(
|
||||
data: ThemeData(
|
||||
textTheme: TextTheme(subtitle1: TextStyle(color: themeColor,fontFamily: 'Lato')),
|
||||
backgroundColor: dividerThemeColor,
|
||||
unselectedWidgetColor: themeColor,
|
||||
accentColor: themeColor)
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 24.0),
|
||||
child: ListTileTheme(
|
||||
contentPadding: EdgeInsets.only(right: 16,top:sectionIndex>0?26:0),
|
||||
child: ExpansionTile(
|
||||
title: sectionTitleBuilder == null
|
||||
? Container()
|
||||
: Container(child: buildTitle(items, sectionIndex, context)),
|
||||
initiallyExpanded: true,
|
||||
children: buildSection(itemCount, items, sectionIndex, context),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
items.add(StandardListSeparator(padding: EdgeInsets.only(left: 24)));
|
||||
return items;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildTitle(
|
||||
List<Widget> items, int sectionIndex, BuildContext context) {
|
||||
final title = sectionTitleBuilder(context, sectionIndex);
|
||||
return title;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> buildSection(int itemCount, List<Widget> items, int sectionIndex,
|
||||
BuildContext context) {
|
||||
final List<Widget> section = [];
|
||||
|
||||
for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
|
||||
final item = itemBuilder(context, sectionIndex, itemIndex);
|
||||
|
||||
section.add(StandardListSeparator());
|
||||
|
||||
section.add(item);
|
||||
|
||||
}
|
||||
return section;
|
||||
}
|
||||
}
|
||||
@@ -120,9 +120,20 @@ class SectionStandardList extends StatelessWidget {
|
||||
@required this.sectionCount,
|
||||
this.sectionTitleBuilder,
|
||||
this.hasTopSeparator = false,
|
||||
this.themeColor,
|
||||
this.dividerThemeColor,
|
||||
BuildContext context})
|
||||
: totalRows = transform(hasTopSeparator, context, sectionCount,
|
||||
itemCounter, itemBuilder, sectionTitleBuilder);
|
||||
: totalRows = [] {
|
||||
totalRows.addAll(transform(
|
||||
hasTopSeparator,
|
||||
context,
|
||||
sectionCount,
|
||||
itemCounter,
|
||||
itemBuilder,
|
||||
sectionTitleBuilder,
|
||||
themeColor,
|
||||
dividerThemeColor));
|
||||
}
|
||||
|
||||
final int sectionCount;
|
||||
final bool hasTopSeparator;
|
||||
@@ -132,8 +143,10 @@ class SectionStandardList extends StatelessWidget {
|
||||
final Widget Function(BuildContext context, int sectionIndex)
|
||||
sectionTitleBuilder;
|
||||
final List<Widget> totalRows;
|
||||
final Color themeColor;
|
||||
final Color dividerThemeColor;
|
||||
|
||||
static List<Widget> transform(
|
||||
List<Widget> transform(
|
||||
bool hasTopSeparator,
|
||||
BuildContext context,
|
||||
int sectionCount,
|
||||
@@ -141,7 +154,9 @@ class SectionStandardList extends StatelessWidget {
|
||||
Widget Function(BuildContext context, int sectionIndex, int itemIndex)
|
||||
itemBuilder,
|
||||
Widget Function(BuildContext context, int sectionIndex)
|
||||
sectionTitleBuilder) {
|
||||
sectionTitleBuilder,
|
||||
Color themeColor,
|
||||
Color dividerThemeColor) {
|
||||
final items = <Widget>[];
|
||||
|
||||
for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) {
|
||||
@@ -150,16 +165,12 @@ class SectionStandardList extends StatelessWidget {
|
||||
}
|
||||
|
||||
if (sectionTitleBuilder != null) {
|
||||
items.add(sectionTitleBuilder(context, sectionIndex));
|
||||
items.add(buildTitle(items, sectionIndex, context));
|
||||
}
|
||||
|
||||
final itemCount = itemCounter(sectionIndex);
|
||||
|
||||
for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
|
||||
final item = itemBuilder(context, sectionIndex, itemIndex);
|
||||
|
||||
items.add(item);
|
||||
}
|
||||
items.addAll(buildSection(itemCount, items, sectionIndex, context));
|
||||
|
||||
items.add(sectionIndex + 1 != sectionCount
|
||||
? SectionHeaderListRow()
|
||||
@@ -169,6 +180,24 @@ class SectionStandardList extends StatelessWidget {
|
||||
return items;
|
||||
}
|
||||
|
||||
Widget buildTitle(
|
||||
List<Widget> items, int sectionIndex, BuildContext context) {
|
||||
final title = sectionTitleBuilder(context, sectionIndex);
|
||||
return title;
|
||||
}
|
||||
|
||||
List<Widget> buildSection(int itemCount, List<Widget> items, int sectionIndex,
|
||||
BuildContext context) {
|
||||
final List<Widget> section = [];
|
||||
|
||||
for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
|
||||
final item = itemBuilder(context, sectionIndex, itemIndex);
|
||||
|
||||
section.add(item);
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
|
||||
Reference in New Issue
Block a user