mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-11 05:14:46 +00:00
fix: SectionStandardList using BuildContext as param
This commit is contained in:
parent
bb75472a83
commit
c893da7a11
10 changed files with 61 additions and 139 deletions
|
@ -42,10 +42,9 @@ class _AnonpayDetailsPageBodyState extends State<AnonpayDetailsPageBody> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => widget.anonpayDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = widget.anonpayDetailsViewModel.items[index];
|
||||
|
||||
if (item is DetailsListStatusItem) {
|
||||
|
|
|
@ -65,12 +65,11 @@ class ContactListPage extends BasePage {
|
|||
final contacts = contactListViewModel.contactsToShow;
|
||||
final walletContacts = contactListViewModel.walletContactsToShow;
|
||||
return CollapsibleSectionList(
|
||||
context: context,
|
||||
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;
|
||||
|
||||
if (sectionIndex == 0) {
|
||||
|
@ -84,7 +83,7 @@ class ContactListPage extends BasePage {
|
|||
itemCounter: (int sectionIndex) => sectionIndex == 0
|
||||
? walletContacts.length
|
||||
: contacts.length,
|
||||
itemBuilder: (_, sectionIndex, index) {
|
||||
itemBuilder: (sectionIndex, index) {
|
||||
if (sectionIndex == 0) {
|
||||
final walletInfo = walletContacts[index];
|
||||
return generateRaw(context, walletInfo);
|
||||
|
|
|
@ -48,10 +48,9 @@ class OrderDetailsPageBodyState extends State<OrderDetailsPageBody> {
|
|||
Widget build(BuildContext context) {
|
||||
return Observer(builder: (_) {
|
||||
return SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => orderDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = orderDetailsViewModel.items[index];
|
||||
|
||||
if (item is TrackTradeListItem) {
|
||||
|
|
|
@ -56,12 +56,11 @@ class ConnectionSyncPage extends BasePage {
|
|||
return Flexible(
|
||||
child: SectionStandardList(
|
||||
sectionCount: 1,
|
||||
context: context,
|
||||
dividerPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
itemCounter: (int sectionIndex) {
|
||||
return nodeListViewModel.nodes.length;
|
||||
},
|
||||
itemBuilder: (_, sectionIndex, index) {
|
||||
itemBuilder: (sectionIndex, index) {
|
||||
final node = nodeListViewModel.nodes[index];
|
||||
final isSelected = node.keyIndex == nodeListViewModel.currentNode.keyIndex;
|
||||
final nodeListRow = Semantics(
|
||||
|
|
|
@ -28,10 +28,9 @@ class SupportPage extends BasePage {
|
|||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => supportViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = supportViewModel.items[index];
|
||||
|
||||
if (item is RegularListItem) {
|
||||
|
|
|
@ -53,10 +53,9 @@ class TradeDetailsPageBodyState extends State<TradeDetailsPageBody> {
|
|||
return Observer(builder: (_) {
|
||||
// FIX-ME: Added `context` it was not used here before, maby bug ?
|
||||
return SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => tradeDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = tradeDetailsViewModel.items[index];
|
||||
|
||||
if (item is TrackTradeListItem) {
|
||||
|
|
|
@ -10,11 +10,6 @@ import 'package:cake_wallet/src/widgets/list_row.dart';
|
|||
import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart';
|
||||
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/utils/date_formatter.dart';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
class TransactionDetailsPage extends BasePage {
|
||||
TransactionDetailsPage({required this.transactionDetailsViewModel});
|
||||
|
@ -28,10 +23,9 @@ class TransactionDetailsPage extends BasePage {
|
|||
Widget body(BuildContext context) {
|
||||
// FIX-ME: Added `context` it was not used here before, maby bug ?
|
||||
return SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => transactionDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = transactionDetailsViewModel.items[index];
|
||||
|
||||
if (item is StandartListItem) {
|
||||
|
|
|
@ -26,10 +26,9 @@ class UnspentCoinsDetailsPage extends BasePage {
|
|||
Widget body(BuildContext context) {
|
||||
// FIX-ME: Added `context` it was not used here before, maby bug ?
|
||||
return SectionStandardList(
|
||||
context: context,
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => unspentCoinsDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
itemBuilder: (__, index) {
|
||||
final item = unspentCoinsDetailsViewModel.items[index];
|
||||
|
||||
if (item is StandartListItem) {
|
||||
|
|
|
@ -3,16 +3,14 @@ import 'package:flutter/material.dart';
|
|||
|
||||
class CollapsibleSectionList extends SectionStandardList {
|
||||
CollapsibleSectionList(
|
||||
{required BuildContext context,
|
||||
required int sectionCount,
|
||||
{required int sectionCount,
|
||||
required int Function(int sectionIndex) itemCounter,
|
||||
required Widget Function(BuildContext context, int sectionIndex, int itemIndex) itemBuilder,
|
||||
required Widget Function(int sectionIndex, int itemIndex) itemBuilder,
|
||||
Color? themeColor,
|
||||
Color? dividerThemeColor,
|
||||
Widget Function(BuildContext context, int sectionIndex)? sectionTitleBuilder,
|
||||
Widget Function(int sectionIndex)? sectionTitleBuilder,
|
||||
bool hasTopSeparator = false})
|
||||
: super(
|
||||
context: context,
|
||||
hasTopSeparator: hasTopSeparator,
|
||||
sectionCount: sectionCount,
|
||||
itemCounter: itemCounter,
|
||||
|
@ -22,71 +20,23 @@ class CollapsibleSectionList extends SectionStandardList {
|
|||
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,
|
||||
Color? themeColor,
|
||||
Color? dividerThemeColor) {
|
||||
final items = <Widget>[];
|
||||
|
||||
for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) {
|
||||
final itemCount = itemCounter(sectionIndex);
|
||||
|
||||
items.add(Theme(
|
||||
data: ThemeData(
|
||||
textTheme: TextTheme(titleMedium: 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(
|
||||
textColor: themeColor,
|
||||
iconColor: themeColor,
|
||||
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) {
|
||||
Widget buildTitle(List<Widget> items, int sectionIndex) {
|
||||
if (sectionTitleBuilder == null) {
|
||||
throw Exception('Cannot to build title. sectionTitleBuilder is null');
|
||||
}
|
||||
return sectionTitleBuilder!.call(context, sectionIndex);
|
||||
return sectionTitleBuilder!.call(sectionIndex);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> buildSection(int itemCount, List<Widget> items, int sectionIndex,
|
||||
BuildContext context) {
|
||||
List<Widget> buildSection(int itemCount, List<Widget> items, int sectionIndex) {
|
||||
final List<Widget> section = [];
|
||||
|
||||
for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
|
||||
final item = itemBuilder(context, sectionIndex, itemIndex);
|
||||
final item = itemBuilder(sectionIndex, itemIndex);
|
||||
|
||||
section.add(StandardListSeparator());
|
||||
|
||||
section.add(item);
|
||||
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import 'package:cake_wallet/src/widgets/standard_list_status_row.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class StandardListRow extends StatelessWidget {
|
||||
StandardListRow(
|
||||
{required this.title, required this.isSelected, this.onTap});
|
||||
StandardListRow({required this.title, required this.isSelected, this.onTap});
|
||||
|
||||
final String title;
|
||||
final bool isSelected;
|
||||
|
@ -39,7 +38,8 @@ class StandardListRow extends StatelessWidget {
|
|||
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
if (hasLeftOffset) SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(title,
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.normal,
|
||||
|
@ -74,7 +74,6 @@ class SectionHeaderListRow extends StatelessWidget {
|
|||
}
|
||||
|
||||
class StandardListSeparator extends StatelessWidget {
|
||||
|
||||
StandardListSeparator({this.padding, this.height = 1});
|
||||
|
||||
final EdgeInsets? padding;
|
||||
|
@ -108,7 +107,6 @@ class StandardList extends StatelessWidget {
|
|||
StandardListSeparator(padding: EdgeInsets.only(left: 24)),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: itemBuilder);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,35 +118,22 @@ class SectionStandardListItem {
|
|||
}
|
||||
|
||||
class SectionStandardList extends StatelessWidget {
|
||||
SectionStandardList(
|
||||
{required this.itemCounter,
|
||||
SectionStandardList({
|
||||
required this.itemCounter,
|
||||
required this.itemBuilder,
|
||||
required this.sectionCount,
|
||||
required BuildContext context,
|
||||
this.dividerPadding = const EdgeInsets.only(left: 24),
|
||||
this.themeColor,
|
||||
this.dividerThemeColor,
|
||||
this.sectionTitleBuilder,
|
||||
this.hasTopSeparator = false,})
|
||||
: totalRows = [] {
|
||||
totalRows.addAll(transform(
|
||||
hasTopSeparator,
|
||||
context,
|
||||
sectionCount,
|
||||
itemCounter,
|
||||
itemBuilder,
|
||||
sectionTitleBuilder,
|
||||
themeColor,
|
||||
dividerThemeColor));
|
||||
}
|
||||
this.hasTopSeparator = false,
|
||||
}) : totalRows = [];
|
||||
|
||||
final int sectionCount;
|
||||
final bool hasTopSeparator;
|
||||
final int Function(int sectionIndex) itemCounter;
|
||||
final Widget Function(BuildContext context, int sectionIndex, int itemIndex)
|
||||
itemBuilder;
|
||||
final Widget Function(BuildContext context, int sectionIndex)?
|
||||
sectionTitleBuilder;
|
||||
final Widget Function(int sectionIndex, int itemIndex) itemBuilder;
|
||||
final Widget Function(int sectionIndex)? sectionTitleBuilder;
|
||||
final List<Widget> totalRows;
|
||||
final Color? themeColor;
|
||||
final Color? dividerThemeColor;
|
||||
|
@ -156,13 +141,10 @@ class SectionStandardList extends StatelessWidget {
|
|||
|
||||
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,
|
||||
Widget Function(int sectionIndex, int itemIndex) itemBuilder,
|
||||
Widget Function(int sectionIndex)? sectionTitleBuilder,
|
||||
Color? themeColor,
|
||||
Color? dividerThemeColor) {
|
||||
final items = <Widget>[];
|
||||
|
@ -173,12 +155,12 @@ class SectionStandardList extends StatelessWidget {
|
|||
}
|
||||
|
||||
if (sectionTitleBuilder != null) {
|
||||
items.add(buildTitle(items, sectionIndex, context));
|
||||
items.add(buildTitle(items, sectionIndex));
|
||||
}
|
||||
|
||||
final itemCount = itemCounter(sectionIndex);
|
||||
|
||||
items.addAll(buildSection(itemCount, items, sectionIndex, context));
|
||||
items.addAll(buildSection(itemCount, items, sectionIndex));
|
||||
|
||||
items.add(sectionIndex + 1 != sectionCount
|
||||
? SectionHeaderListRow()
|
||||
|
@ -188,21 +170,20 @@ class SectionStandardList extends StatelessWidget {
|
|||
return items;
|
||||
}
|
||||
|
||||
Widget buildTitle(
|
||||
List<Widget> items, int sectionIndex, BuildContext context) {
|
||||
Widget buildTitle(List<Widget> items, int sectionIndex) {
|
||||
if (sectionTitleBuilder == null) {
|
||||
throw Exception('Cannot to build title. sectionTitleBuilder is null');
|
||||
}
|
||||
|
||||
return sectionTitleBuilder!.call(context, sectionIndex);
|
||||
return sectionTitleBuilder!.call(sectionIndex);
|
||||
}
|
||||
|
||||
List<Widget> buildSection(int itemCount, List<Widget> items, int sectionIndex,
|
||||
BuildContext context) {
|
||||
List<Widget> buildSection(
|
||||
int itemCount, List<Widget> items, int sectionIndex) {
|
||||
final List<Widget> section = [];
|
||||
|
||||
for (var itemIndex = 0; itemIndex < itemCount; itemIndex++) {
|
||||
final item = itemBuilder(context, sectionIndex, itemIndex);
|
||||
final item = itemBuilder(sectionIndex, itemIndex);
|
||||
|
||||
section.add(item);
|
||||
}
|
||||
|
@ -211,6 +192,9 @@ class SectionStandardList extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
totalRows.addAll(transform(hasTopSeparator, sectionCount, itemCounter,
|
||||
itemBuilder, sectionTitleBuilder, themeColor, dividerThemeColor));
|
||||
|
||||
return ListView.separated(
|
||||
separatorBuilder: (_, index) {
|
||||
final row = totalRows[index];
|
||||
|
@ -219,7 +203,8 @@ class SectionStandardList extends StatelessWidget {
|
|||
return Container();
|
||||
}
|
||||
|
||||
if (row is StandardListStatusRow || row is TradeDetailsStandardListCard) {
|
||||
if (row is StandardListStatusRow ||
|
||||
row is TradeDetailsStandardListCard) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue