stack_wallet/lib/pages/ordinals/ordinal_details_view.dart

271 lines
8.2 KiB
Dart
Raw Normal View History

2023-07-18 17:03:57 +00:00
import 'dart:async';
2023-07-18 16:15:05 +00:00
import 'package:flutter/material.dart';
2023-07-18 17:03:57 +00:00
import 'package:flutter/services.dart';
2023-07-18 16:15:05 +00:00
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
import 'package:stackwallet/models/ordinal.dart';
2023-07-18 17:03:57 +00:00
import 'package:stackwallet/notifications/show_flush_bar.dart';
2023-07-18 17:26:43 +00:00
import 'package:stackwallet/pages/ordinals/widgets/dialogs.dart';
2023-07-18 16:15:05 +00:00
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
2023-07-18 17:03:57 +00:00
import 'package:stackwallet/widgets/rounded_white_container.dart';
2023-07-18 16:15:05 +00:00
class OrdinalDetailsView extends StatefulWidget {
const OrdinalDetailsView({
Key? key,
2023-07-18 16:15:05 +00:00
required this.walletId,
required this.ordinal,
}) : super(key: key);
2023-07-18 16:15:05 +00:00
final String walletId;
final Ordinal ordinal;
2023-07-18 16:15:05 +00:00
static const routeName = "/ordinalDetailsView";
@override
_OrdinalDetailsViewState createState() => _OrdinalDetailsViewState();
2023-07-18 16:15:05 +00:00
}
class _OrdinalDetailsViewState extends State<OrdinalDetailsView> {
2023-07-18 17:03:57 +00:00
static const _spacing = 12.0;
2023-07-18 16:15:05 +00:00
@override
Widget build(BuildContext context) {
return Background(
child: SafeArea(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
2023-07-18 16:15:05 +00:00
appBar: AppBar(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
2023-07-18 16:15:05 +00:00
leading: const AppBarBackButton(),
title: Text(
"Ordinal details",
style: STextStyles.navBarTitle(context),
),
),
2023-07-18 17:03:57 +00:00
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 39,
),
child: _OrdinalImageGroup(
ordinal: widget.ordinal,
2023-07-18 17:03:57 +00:00
walletId: widget.walletId,
),
),
_DetailsItemWCopy(
title: "Inscription number",
data: widget.ordinal.inscriptionNumber.toString(),
2023-07-18 17:03:57 +00:00
),
const SizedBox(
height: _spacing,
),
_DetailsItemWCopy(
title: "ID",
data: widget.ordinal.inscriptionId,
2023-07-18 17:03:57 +00:00
),
const SizedBox(
height: _spacing,
),
// todo: add utxo status
const SizedBox(
height: _spacing,
),
const _DetailsItemWCopy(
2023-07-18 17:03:57 +00:00
title: "Amount",
data: "TODO", // TODO infer from utxo utxoTXID:utxoVOUT
2023-07-18 17:03:57 +00:00
),
const SizedBox(
height: _spacing,
),
const _DetailsItemWCopy(
2023-07-18 17:03:57 +00:00
title: "Owner address",
data: "TODO", // infer from address associated w utxoTXID
2023-07-18 17:03:57 +00:00
),
const SizedBox(
height: _spacing,
),
_DetailsItemWCopy(
title: "Transaction ID",
data: widget.ordinal.utxoTXID,
2023-07-18 17:03:57 +00:00
),
const SizedBox(
height: _spacing,
),
],
),
),
),
2023-07-18 16:15:05 +00:00
),
),
);
}
}
2023-07-18 17:03:57 +00:00
class _DetailsItemWCopy extends StatelessWidget {
const _DetailsItemWCopy({
Key? key,
2023-07-18 17:03:57 +00:00
required this.title,
required this.data,
}) : super(key: key);
2023-07-18 17:03:57 +00:00
final String title;
final String data;
@override
Widget build(BuildContext context) {
return RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: STextStyles.itemSubtitle(context),
),
GestureDetector(
onTap: () async {
await Clipboard.setData(ClipboardData(text: data));
if (context.mounted) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
},
child: SvgPicture.asset(
Assets.svg.copy,
color:
Theme.of(context).extension<StackColors>()!.infoItemIcons,
2023-07-18 17:03:57 +00:00
width: 12,
),
),
],
),
const SizedBox(
height: 4,
),
SelectableText(
data,
style: STextStyles.itemSubtitle12(context),
),
],
),
);
}
}
2023-07-18 16:15:05 +00:00
class _OrdinalImageGroup extends StatelessWidget {
const _OrdinalImageGroup({
Key? key,
2023-07-18 17:03:57 +00:00
required this.walletId,
required this.ordinal,
}) : super(key: key);
2023-07-18 16:15:05 +00:00
2023-07-18 17:03:57 +00:00
final String walletId;
final Ordinal ordinal;
2023-07-18 16:15:05 +00:00
static const _spacing = 12.0;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Text(
// "${ordinal.inscriptionId}", // Use any other property you want
// style: STextStyles.w600_16(context),
// ),
// const SizedBox(
// height: _spacing,
// ),
2023-07-18 16:15:05 +00:00
AspectRatio(
aspectRatio: 1,
2023-07-21 15:49:30 +00:00
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.red,
child: Image.network(
ordinal.content, // Use the preview URL as the image source
2023-07-21 15:49:30 +00:00
fit: BoxFit.cover,
filterQuality: FilterQuality.none, // Set the filter mode to nearest
),
),
2023-07-18 16:15:05 +00:00
),
),
const SizedBox(
height: _spacing,
),
Row(
children: [
Expanded(
child: SecondaryButton(
label: "Download",
2023-07-18 17:03:57 +00:00
icon: SvgPicture.asset(
Assets.svg.arrowDown,
width: 10,
height: 12,
color: Theme.of(context)
.extension<StackColors>()!
.buttonTextSecondary,
),
buttonHeight: ButtonHeight.l,
iconSpacing: 4,
2023-07-18 16:15:05 +00:00
onPressed: () {
// TODO: save and download image to device
},
),
),
const SizedBox(
width: _spacing,
),
Expanded(
child: PrimaryButton(
label: "Send",
icon: SvgPicture.asset(
2023-07-18 17:03:57 +00:00
Assets.svg.send,
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.buttonTextPrimary,
2023-07-18 16:15:05 +00:00
),
2023-07-18 17:03:57 +00:00
buttonHeight: ButtonHeight.l,
iconSpacing: 4,
2023-07-18 17:26:43 +00:00
onPressed: () async {
final response = await showDialog<String?>(
context: context,
builder: (_) => const SendOrdinalUnfreezeDialog(),
);
if (response == "unfreeze") {
// TODO: unfreeze and go to send ord screen
}
2023-07-18 16:15:05 +00:00
},
),
),
],
),
],
);
}
}