mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
hook OrdinalsList up to OrdinalsInterface
This commit is contained in:
parent
c295ca9a6f
commit
f750bbfe10
3 changed files with 57 additions and 51 deletions
|
@ -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(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -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 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: widget.ordinals.length,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisSpacing: spacing,
|
||||
mainAxisSpacing: spacing,
|
||||
itemCount: inscriptions.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisSpacing: spacing as double,
|
||||
mainAxisSpacing: spacing as double,
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 3 / 4,
|
||||
),
|
||||
itemBuilder: (_, i) => OrdinalCard(
|
||||
walletId: widget.walletId,
|
||||
ordinal: widget.ordinals[i],
|
||||
walletId: walletId,
|
||||
inscriptionData: inscriptions[i],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Text('No data found.');
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue