refactor: collapsible_standart_list improvements

This commit is contained in:
Rafael Saes 2023-07-03 13:15:36 -03:00
parent 8c7685c01b
commit 7d55092704
3 changed files with 41 additions and 56 deletions

View file

@ -54,18 +54,13 @@ class ContactListPage extends BasePage {
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.only(top: 20.0, bottom: 20.0), padding: EdgeInsets.all(24),
child: Observer( child: Observer(builder: (_) {
builder: (_) {
final contacts = contactListViewModel.contactsToShow; final contacts = contactListViewModel.contactsToShow;
final walletContacts = contactListViewModel.walletContactsToShow; final walletContacts = contactListViewModel.walletContactsToShow;
return CollapsibleSectionList( return CollapsibleSectionList(
sectionCount: 2, sectionCount: 2,
themeColor: Theme.of(context).primaryTextTheme!.titleLarge!.color!,
dividerThemeColor:
Theme.of(context).primaryTextTheme!.bodySmall!.decorationColor!,
sectionTitleBuilder: (int sectionIndex) { sectionTitleBuilder: (int sectionIndex) {
var title = S.current.contact_list_contacts; var title = S.current.contact_list_contacts;
@ -75,11 +70,15 @@ class ContactListPage extends BasePage {
return Container( return Container(
padding: EdgeInsets.only(bottom: 10), padding: EdgeInsets.only(bottom: 10),
child: Text(title, style: TextStyle(fontSize: 36))); child: Text(title, style: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.titleLarge!
.color!,
fontSize: 36)));
}, },
itemCounter: (int sectionIndex) => sectionIndex == 0 itemCounter: (int sectionIndex) =>
? walletContacts.length sectionIndex == 0 ? walletContacts.length : contacts.length,
: contacts.length,
itemBuilder: (sectionIndex, index) { itemBuilder: (sectionIndex, index) {
if (sectionIndex == 0) { if (sectionIndex == 0) {
final walletInfo = walletContacts[index]; final walletInfo = walletContacts[index];
@ -96,8 +95,8 @@ class ContactListPage extends BasePage {
) )
: content; : content;
}, },
);})
); );
}));
} }
Widget generateRaw(BuildContext context, ContactBase contact) { Widget generateRaw(BuildContext context, ContactBase contact) {

View file

@ -6,8 +6,6 @@ class CollapsibleSectionList extends SectionStandardList {
{required int sectionCount, {required int sectionCount,
required int Function(int sectionIndex) itemCounter, required int Function(int sectionIndex) itemCounter,
required Widget Function(int sectionIndex, int itemIndex) itemBuilder, required Widget Function(int sectionIndex, int itemIndex) itemBuilder,
Color? themeColor,
Color? dividerThemeColor,
Widget Function(int sectionIndex)? sectionTitleBuilder, Widget Function(int sectionIndex)? sectionTitleBuilder,
bool hasTopSeparator = false}) bool hasTopSeparator = false})
: super( : super(
@ -15,9 +13,7 @@ class CollapsibleSectionList extends SectionStandardList {
sectionCount: sectionCount, sectionCount: sectionCount,
itemCounter: itemCounter, itemCounter: itemCounter,
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
sectionTitleBuilder: sectionTitleBuilder, sectionTitleBuilder: sectionTitleBuilder);
themeColor: themeColor,
dividerThemeColor: dividerThemeColor);
@override @override
Widget buildTitle(List<Widget> items, int sectionIndex) { Widget buildTitle(List<Widget> items, int sectionIndex) {

View file

@ -18,7 +18,7 @@ class StandardListRow extends StatelessWidget {
return InkWell( return InkWell(
onTap: () => onTap?.call(context), onTap: () => onTap?.call(context),
child: Container( child: Container(
color: _backgroundColor(context), color: Theme.of(context).colorScheme.background,
height: 56, height: 56,
padding: EdgeInsets.only(left: 24, right: 24), padding: EdgeInsets.only(left: 24, right: 24),
child: Row( child: Row(
@ -54,11 +54,7 @@ class StandardListRow extends StatelessWidget {
Color titleColor(BuildContext context) => isSelected Color titleColor(BuildContext context) => isSelected
? Palette.blueCraiola ? Palette.blueCraiola
: Theme.of(context).primaryTextTheme!.titleLarge!.color!; : Theme.of(context).primaryTextTheme.titleLarge!.color!;
Color _backgroundColor(BuildContext context) {
return Theme.of(context).colorScheme.background;
}
} }
class SectionHeaderListRow extends StatelessWidget { class SectionHeaderListRow extends StatelessWidget {
@ -123,8 +119,6 @@ class SectionStandardList extends StatelessWidget {
required this.itemBuilder, required this.itemBuilder,
required this.sectionCount, required this.sectionCount,
this.dividerPadding = const EdgeInsets.only(left: 24), this.dividerPadding = const EdgeInsets.only(left: 24),
this.themeColor,
this.dividerThemeColor,
this.sectionTitleBuilder, this.sectionTitleBuilder,
this.hasTopSeparator = false, this.hasTopSeparator = false,
}) : totalRows = []; }) : totalRows = [];
@ -135,8 +129,6 @@ class SectionStandardList extends StatelessWidget {
final Widget Function(int sectionIndex, int itemIndex) itemBuilder; final Widget Function(int sectionIndex, int itemIndex) itemBuilder;
final Widget Function(int sectionIndex)? sectionTitleBuilder; final Widget Function(int sectionIndex)? sectionTitleBuilder;
final List<Widget> totalRows; final List<Widget> totalRows;
final Color? themeColor;
final Color? dividerThemeColor;
final EdgeInsets dividerPadding; final EdgeInsets dividerPadding;
List<Widget> transform( List<Widget> transform(
@ -144,9 +136,7 @@ class SectionStandardList extends StatelessWidget {
int sectionCount, int sectionCount,
int Function(int sectionIndex) itemCounter, int Function(int sectionIndex) itemCounter,
Widget Function(int sectionIndex, int itemIndex) itemBuilder, Widget Function(int sectionIndex, int itemIndex) itemBuilder,
Widget Function(int sectionIndex)? sectionTitleBuilder, Widget Function(int sectionIndex)? sectionTitleBuilder) {
Color? themeColor,
Color? dividerThemeColor) {
final items = <Widget>[]; final items = <Widget>[];
for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) { for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) {
@ -193,7 +183,7 @@ class SectionStandardList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
totalRows.addAll(transform(hasTopSeparator, sectionCount, itemCounter, totalRows.addAll(transform(hasTopSeparator, sectionCount, itemCounter,
itemBuilder, sectionTitleBuilder, themeColor, dividerThemeColor)); itemBuilder, sectionTitleBuilder));
return ListView.separated( return ListView.separated(
separatorBuilder: (_, index) { separatorBuilder: (_, index) {