diff --git a/lib/src/screens/contact/contact_list_page.dart b/lib/src/screens/contact/contact_list_page.dart index dca2afdf8..7a46e99c3 100644 --- a/lib/src/screens/contact/contact_list_page.dart +++ b/lib/src/screens/contact/contact_list_page.dart @@ -12,7 +12,7 @@ import 'package:cw_core/crypto_currency.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; -import 'package:cake_wallet/src/widgets/standard_list.dart'; +import 'package:cake_wallet/src/widgets/collapsible_standart_list.dart'; class ContactListPage extends BasePage { ContactListPage(this.contactListViewModel, {this.isEditable = true}); @@ -62,9 +62,12 @@ class ContactListPage extends BasePage { padding: EdgeInsets.only(top: 20.0, bottom: 20.0), child: Observer( builder: (_) { - return SectionStandardList( + return CollapsibleSectionList( context: context, sectionCount: 2, + themeColor: Theme.of(context).primaryTextTheme.title.color, + dividerThemeColor: + Theme.of(context).primaryTextTheme.caption.decorationColor, sectionTitleBuilder: (_, int sectionIndex) { var title = 'Contacts'; @@ -73,7 +76,7 @@ class ContactListPage extends BasePage { } return Container( - padding: EdgeInsets.only(left: 24, bottom: 20), + padding: EdgeInsets.only(bottom: 10), child: Text(title, style: TextStyle(fontSize: 36))); }, itemCounter: (int sectionIndex) => sectionIndex == 0 @@ -144,11 +147,10 @@ class ContactListPage extends BasePage { child: Container( color: Colors.transparent, padding: - const EdgeInsets.only(left: 24, top: 16, bottom: 16, right: 24), + const EdgeInsets.only(top: 16, bottom: 16, right: 24), child: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, children: [ image ?? Offstage(), Expanded( diff --git a/lib/src/widgets/collapsible_standart_list.dart b/lib/src/widgets/collapsible_standart_list.dart new file mode 100644 index 000000000..1f7c5d91f --- /dev/null +++ b/lib/src/widgets/collapsible_standart_list.dart @@ -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 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 = []; + + 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 items, int sectionIndex, BuildContext context) { + final title = sectionTitleBuilder(context, sectionIndex); + return title; + } + + @override + List buildSection(int itemCount, List items, int sectionIndex, + BuildContext context) { + final List section = []; + + for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) { + final item = itemBuilder(context, sectionIndex, itemIndex); + + section.add(StandardListSeparator()); + + section.add(item); + + } + return section; + } +} diff --git a/lib/src/widgets/standard_list.dart b/lib/src/widgets/standard_list.dart index c9c555e81..c12f1b347 100644 --- a/lib/src/widgets/standard_list.dart +++ b/lib/src/widgets/standard_list.dart @@ -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 totalRows; + final Color themeColor; + final Color dividerThemeColor; - static List transform( + List 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 = []; 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 items, int sectionIndex, BuildContext context) { + final title = sectionTitleBuilder(context, sectionIndex); + return title; + } + + List buildSection(int itemCount, List items, int sectionIndex, + BuildContext context) { + final List 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(