hook OrdinalsList up to OrdinalsInterface

This commit is contained in:
sneurlax 2023-07-21 10:30:47 -05:00
parent c295ca9a6f
commit f750bbfe10
3 changed files with 57 additions and 51 deletions

View file

@ -56,6 +56,14 @@ class _OrdinalsViewState extends ConsumerState<OrdinalsView> {
super.initState();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Set _manager here when the widget's dependencies change
_manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId)));
}
@override
void dispose() {
searchController.dispose();
@ -92,8 +100,6 @@ class _OrdinalsViewState extends ConsumerState<OrdinalsView> {
.topNavIconPrimary,
),
onPressed: () async {
_manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId)));
(_manager.wallet as OrdinalsInterface).refreshInscriptions();
},
),
@ -187,17 +193,7 @@ class _OrdinalsViewState extends ConsumerState<OrdinalsView> {
Expanded(
child: OrdinalsList(
walletId: widget.walletId,
ordinals: [
for (int i = 0; i < 13; i++)
Ordinal(
name: "dummy name $i",
inscription: "insc$i",
rank: "r$i",
collection: OrdCollection.moonbirds,
utxoTXID: 'txid',
utxoVOUT: 1
),
],
ordinalsFuture: (_manager.wallet as OrdinalsInterface).getInscriptions(),
),
),
],

View file

@ -1,18 +1,19 @@
import 'package:flutter/material.dart';
import 'package:stackwallet/models/ordinal.dart';
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
import 'package:stackwallet/models/ordinal.dart'; // TODO generalize InscriptionData models -> Ordinal
import 'package:stackwallet/pages/ordinals/ordinal_details_view.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class OrdinalCard extends StatelessWidget {
const OrdinalCard({
super.key,
Key? key,
required this.walletId,
required this.ordinal,
});
required this.inscriptionData,
}) : super(key: key);
final String walletId;
final Ordinal ordinal;
final InscriptionData inscriptionData;
@override
Widget build(BuildContext context) {
@ -21,7 +22,7 @@ class OrdinalCard extends StatelessWidget {
onPressed: () {
Navigator.of(context).pushNamed(
OrdinalDetailsView.routeName,
arguments: (walletId: walletId, ordinal: ordinal),
arguments: (walletId: walletId, inscriptionData: inscriptionData),
);
},
child: Column(
@ -31,21 +32,20 @@ class OrdinalCard extends StatelessWidget {
aspectRatio: 1,
child: Container(
color: Colors.red,
child: const Center(
child: Text(
"replace red container with image",
),
child: Image.network(
inscriptionData.preview, // Use the preview URL as the image source
fit: BoxFit.cover,
),
),
),
const Spacer(),
Text(
ordinal.name,
inscriptionData.address,
style: STextStyles.w500_12(context),
),
const Spacer(),
Text(
"INSC. ${ordinal.inscription} RANK ${ordinal.rank}",
"INSC. ${inscriptionData.inscriptionNumber} ID ${inscriptionData.inscriptionId}",
style: STextStyles.w500_8(context),
),
],

View file

@ -1,39 +1,49 @@
import 'package:flutter/material.dart';
import 'package:stackwallet/models/ordinal.dart';
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
import 'package:stackwallet/pages/ordinals/widgets/ordinal_card.dart';
class OrdinalsList extends StatefulWidget {
class OrdinalsList extends StatelessWidget {
const OrdinalsList({
super.key,
Key? key,
required this.walletId,
required this.ordinals,
});
required this.ordinalsFuture,
}) : super(key: key);
final String walletId;
final List<Ordinal> ordinals;
final Future<List<InscriptionData>> ordinalsFuture;
@override
State<OrdinalsList> createState() => _OrdinalsListState();
}
class _OrdinalsListState extends State<OrdinalsList> {
static const spacing = 10.0;
get spacing => 2.0;
@override
Widget build(BuildContext context) {
return GridView.builder(
shrinkWrap: true,
itemCount: widget.ordinals.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisSpacing: spacing,
mainAxisSpacing: spacing,
crossAxisCount: 2,
childAspectRatio: 3 / 4,
),
itemBuilder: (_, i) => OrdinalCard(
walletId: widget.walletId,
ordinal: widget.ordinals[i],
),
return FutureBuilder<List<InscriptionData>>(
future: ordinalsFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
final List<InscriptionData> inscriptions = snapshot.data!;
return GridView.builder(
shrinkWrap: true,
itemCount: inscriptions.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisSpacing: spacing as double,
mainAxisSpacing: spacing as double,
crossAxisCount: 2,
childAspectRatio: 3 / 4,
),
itemBuilder: (_, i) => OrdinalCard(
walletId: walletId,
inscriptionData: inscriptions[i],
),
);
} else {
return Text('No data found.');
}
},
);
}
}
}