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,50 +54,49 @@ class ContactListPage extends BasePage {
@override
Widget body(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 20.0, bottom: 20.0),
child: Observer(
builder: (_) {
padding: EdgeInsets.all(24),
child: Observer(builder: (_) {
final contacts = contactListViewModel.contactsToShow;
final walletContacts = contactListViewModel.walletContactsToShow;
return CollapsibleSectionList(
sectionCount: 2,
themeColor: Theme.of(context).primaryTextTheme!.titleLarge!.color!,
dividerThemeColor:
Theme.of(context).primaryTextTheme!.bodySmall!.decorationColor!,
sectionTitleBuilder: (int sectionIndex) {
var title = S.current.contact_list_contacts;
sectionCount: 2,
sectionTitleBuilder: (int sectionIndex) {
var title = S.current.contact_list_contacts;
if (sectionIndex == 0) {
title = S.current.contact_list_wallets;
}
if (sectionIndex == 0) {
title = S.current.contact_list_wallets;
}
return Container(
padding: EdgeInsets.only(bottom: 10),
child: Text(title, style: TextStyle(fontSize: 36)));
},
itemCounter: (int sectionIndex) => sectionIndex == 0
? walletContacts.length
: contacts.length,
itemBuilder: (sectionIndex, index) {
if (sectionIndex == 0) {
final walletInfo = walletContacts[index];
return generateRaw(context, walletInfo);
}
return Container(
padding: EdgeInsets.only(bottom: 10),
child: Text(title, style: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.titleLarge!
.color!,
fontSize: 36)));
},
itemCounter: (int sectionIndex) =>
sectionIndex == 0 ? walletContacts.length : contacts.length,
itemBuilder: (sectionIndex, index) {
if (sectionIndex == 0) {
final walletInfo = walletContacts[index];
return generateRaw(context, walletInfo);
}
final contact = contacts[index];
final content = generateRaw(context, contact);
return contactListViewModel.isEditable
? Slidable(
key: Key('${contact.key}'),
endActionPane: _actionPane(context, contact),
child: content,
)
: content;
},
);})
);
final contact = contacts[index];
final content = generateRaw(context, contact);
return contactListViewModel.isEditable
? Slidable(
key: Key('${contact.key}'),
endActionPane: _actionPane(context, contact),
child: content,
)
: content;
},
);
}));
}
Widget generateRaw(BuildContext context, ContactBase contact) {

View file

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

View file

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