mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
changed generate monkey structure
This commit is contained in:
parent
2eb10e249f
commit
032061fa19
3 changed files with 520 additions and 345 deletions
|
@ -1,265 +1,275 @@
|
||||||
import 'dart:io';
|
// import 'dart:io';
|
||||||
|
// import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
//
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
// import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
// import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:http/http.dart' as http;
|
// import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
// import 'package:http/http.dart' as http;
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
// import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
// import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
// import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
||||||
import 'package:stackwallet/services/coins/manager.dart';
|
// import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
// import 'package:stackwallet/services/coins/banano/banano_wallet.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
// import 'package:stackwallet/services/coins/manager.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
// import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
// import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
// import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
// import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
// import 'package:stackwallet/widgets/background.dart';
|
||||||
|
// import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
class MonkeyLoadedView extends ConsumerStatefulWidget {
|
// import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
const MonkeyLoadedView({
|
//
|
||||||
Key? key,
|
// class MonkeyLoadedView extends ConsumerStatefulWidget {
|
||||||
required this.walletId,
|
// const MonkeyLoadedView({
|
||||||
required this.managerProvider,
|
// Key? key,
|
||||||
}) : super(key: key);
|
// required this.walletId,
|
||||||
|
// required this.managerProvider,
|
||||||
static const String routeName = "/hasMonkey";
|
// }) : super(key: key);
|
||||||
static const double navBarHeight = 65.0;
|
//
|
||||||
|
// static const String routeName = "/hasMonkey";
|
||||||
final String walletId;
|
// static const double navBarHeight = 65.0;
|
||||||
final ChangeNotifierProvider<Manager> managerProvider;
|
//
|
||||||
|
// final String walletId;
|
||||||
@override
|
// final ChangeNotifierProvider<Manager> managerProvider;
|
||||||
ConsumerState<MonkeyLoadedView> createState() => _MonkeyLoadedViewState();
|
//
|
||||||
}
|
// @override
|
||||||
|
// ConsumerState<MonkeyLoadedView> createState() => _MonkeyLoadedViewState();
|
||||||
class _MonkeyLoadedViewState extends ConsumerState<MonkeyLoadedView> {
|
// }
|
||||||
late final String walletId;
|
//
|
||||||
late final ChangeNotifierProvider<Manager> managerProvider;
|
// class _MonkeyLoadedViewState extends ConsumerState<MonkeyLoadedView> {
|
||||||
|
// late final String walletId;
|
||||||
String receivingAddress = "";
|
// late final ChangeNotifierProvider<Manager> managerProvider;
|
||||||
|
//
|
||||||
void getMonkeySVG(String address) async {
|
// String receivingAddress = "";
|
||||||
if (address.isEmpty) {
|
//
|
||||||
//address shouldn't be empty
|
// void getMonkeySVG(String address) async {
|
||||||
return;
|
// if (address.isEmpty) {
|
||||||
}
|
// //address shouldn't be empty
|
||||||
|
// return;
|
||||||
final http.Response response = await http
|
// }
|
||||||
.get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
//
|
||||||
|
// final http.Response response = await http
|
||||||
if (response.statusCode == 200) {
|
// .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
||||||
final decodedResponse = response.bodyBytes;
|
//
|
||||||
Directory directory = await getApplicationDocumentsDirectory();
|
// if (response.statusCode == 200) {
|
||||||
late Directory sampleFolder;
|
// final decodedResponse = response.bodyBytes;
|
||||||
|
// Directory directory = await getApplicationDocumentsDirectory();
|
||||||
if (Platform.isAndroid) {
|
// late Directory sampleFolder;
|
||||||
directory = Directory("/storage/emulated/0/");
|
//
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// if (Platform.isAndroid) {
|
||||||
} else if (Platform.isIOS) {
|
// directory = Directory("/storage/emulated/0/");
|
||||||
sampleFolder = Directory(directory!.path);
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
} else if (Platform.isLinux) {
|
// } else if (Platform.isIOS) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory(directory!.path);
|
||||||
} else if (Platform.isWindows) {
|
// } else if (Platform.isLinux) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
} else if (Platform.isMacOS) {
|
// } else if (Platform.isWindows) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
}
|
// } else if (Platform.isMacOS) {
|
||||||
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
try {
|
// }
|
||||||
if (!sampleFolder.existsSync()) {
|
//
|
||||||
sampleFolder.createSync(recursive: true);
|
// try {
|
||||||
}
|
// if (!sampleFolder.existsSync()) {
|
||||||
} catch (e, s) {
|
// sampleFolder.createSync(recursive: true);
|
||||||
// todo: come back to this
|
// }
|
||||||
debugPrint("$e $s");
|
// } catch (e, s) {
|
||||||
}
|
// // todo: come back to this
|
||||||
|
// debugPrint("$e $s");
|
||||||
final docPath = sampleFolder.path;
|
// }
|
||||||
final filePath = "$docPath/monkey.svg";
|
//
|
||||||
|
// final docPath = sampleFolder.path;
|
||||||
File imgFile = File(filePath);
|
// final filePath = "$docPath/monkey.svg";
|
||||||
await imgFile.writeAsBytes(decodedResponse);
|
//
|
||||||
} else {
|
// File imgFile = File(filePath);
|
||||||
throw Exception("Failed to get MonKey");
|
// await imgFile.writeAsBytes(decodedResponse);
|
||||||
}
|
// } else {
|
||||||
}
|
// throw Exception("Failed to get MonKey");
|
||||||
|
// }
|
||||||
void getMonkeyPNG(String address) async {
|
// }
|
||||||
if (address.isEmpty) {
|
//
|
||||||
//address shouldn't be empty
|
// void getMonkeyPNG(String address) async {
|
||||||
return;
|
// if (address.isEmpty) {
|
||||||
}
|
// //address shouldn't be empty
|
||||||
|
// return;
|
||||||
final http.Response response = await http.get(Uri.parse(
|
// }
|
||||||
'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false'));
|
//
|
||||||
|
// final http.Response response = await http.get(Uri.parse(
|
||||||
if (response.statusCode == 200) {
|
// 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false'));
|
||||||
if (Platform.isAndroid) {
|
//
|
||||||
await Permission.storage.request();
|
// if (response.statusCode == 200) {
|
||||||
}
|
// if (Platform.isAndroid) {
|
||||||
|
// await Permission.storage.request();
|
||||||
final decodedResponse = response.bodyBytes;
|
// }
|
||||||
Directory directory = await getApplicationDocumentsDirectory();
|
//
|
||||||
late Directory sampleFolder;
|
// final decodedResponse = response.bodyBytes;
|
||||||
|
// Directory directory = await getApplicationDocumentsDirectory();
|
||||||
if (Platform.isAndroid) {
|
// late Directory sampleFolder;
|
||||||
directory = Directory("/storage/emulated/0/");
|
//
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// if (Platform.isAndroid) {
|
||||||
} else if (Platform.isIOS) {
|
// directory = Directory("/storage/emulated/0/");
|
||||||
sampleFolder = Directory(directory!.path);
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
} else if (Platform.isLinux) {
|
// } else if (Platform.isIOS) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory(directory!.path);
|
||||||
} else if (Platform.isWindows) {
|
// } else if (Platform.isLinux) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
} else if (Platform.isMacOS) {
|
// } else if (Platform.isWindows) {
|
||||||
sampleFolder = Directory('${directory!.path}Documents');
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
}
|
// } else if (Platform.isMacOS) {
|
||||||
|
// sampleFolder = Directory('${directory!.path}Documents');
|
||||||
try {
|
// }
|
||||||
if (!sampleFolder.existsSync()) {
|
//
|
||||||
sampleFolder.createSync(recursive: true);
|
// try {
|
||||||
}
|
// if (!sampleFolder.existsSync()) {
|
||||||
} catch (e, s) {
|
// sampleFolder.createSync(recursive: true);
|
||||||
// todo: come back to this
|
// }
|
||||||
debugPrint("$e $s");
|
// } catch (e, s) {
|
||||||
}
|
// // todo: come back to this
|
||||||
|
// debugPrint("$e $s");
|
||||||
final docPath = sampleFolder.path;
|
// }
|
||||||
final filePath = "$docPath/monkey.png";
|
//
|
||||||
|
// final docPath = sampleFolder.path;
|
||||||
File imgFile = File(filePath);
|
// final filePath = "$docPath/monkey.png";
|
||||||
await imgFile.writeAsBytes(decodedResponse);
|
//
|
||||||
} else {
|
// File imgFile = File(filePath);
|
||||||
throw Exception("Failed to get MonKey");
|
// await imgFile.writeAsBytes(decodedResponse);
|
||||||
}
|
// } else {
|
||||||
}
|
// throw Exception("Failed to get MonKey");
|
||||||
|
// }
|
||||||
@override
|
// }
|
||||||
void initState() {
|
//
|
||||||
walletId = widget.walletId;
|
// @override
|
||||||
managerProvider = widget.managerProvider;
|
// void initState() {
|
||||||
|
// walletId = widget.walletId;
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
// managerProvider = widget.managerProvider;
|
||||||
final address = await ref
|
//
|
||||||
.read(walletsChangeNotifierProvider)
|
// WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||||
.getManager(walletId)
|
// final address = await ref
|
||||||
.currentReceivingAddress;
|
// .read(walletsChangeNotifierProvider)
|
||||||
setState(() {
|
// .getManager(walletId)
|
||||||
receivingAddress = address;
|
// .currentReceivingAddress;
|
||||||
});
|
// setState(() {
|
||||||
});
|
// receivingAddress = address;
|
||||||
|
// });
|
||||||
super.initState();
|
// });
|
||||||
}
|
//
|
||||||
|
// super.initState();
|
||||||
@override
|
// }
|
||||||
void dispose() {
|
//
|
||||||
super.dispose();
|
// @override
|
||||||
}
|
// void dispose() {
|
||||||
|
// super.dispose();
|
||||||
@override
|
// }
|
||||||
Widget build(BuildContext context) {
|
//
|
||||||
final Coin coin = ref.watch(managerProvider.select((value) => value.coin));
|
// @override
|
||||||
|
// Widget build(BuildContext context) {
|
||||||
return Background(
|
// final Coin coin = ref.watch(managerProvider.select((value) => value.coin));
|
||||||
child: Stack(
|
// final manager = ref.watch(walletsChangeNotifierProvider
|
||||||
children: [
|
// .select((value) => value.getManager(widget.walletId)));
|
||||||
Scaffold(
|
//
|
||||||
appBar: AppBar(
|
// List<int>? imageBytes;
|
||||||
leading: AppBarBackButton(
|
// imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes();
|
||||||
onPressed: () {
|
//
|
||||||
Navigator.of(context).popUntil(
|
// return Background(
|
||||||
ModalRoute.withName(WalletView.routeName),
|
// child: Stack(
|
||||||
);
|
// children: [
|
||||||
},
|
// Scaffold(
|
||||||
),
|
// appBar: AppBar(
|
||||||
title: Text(
|
// leading: AppBarBackButton(
|
||||||
"MonKey",
|
// onPressed: () {
|
||||||
style: STextStyles.navBarTitle(context),
|
// Navigator.of(context).popUntil(
|
||||||
),
|
// ModalRoute.withName(WalletView.routeName),
|
||||||
actions: [
|
// );
|
||||||
AspectRatio(
|
// },
|
||||||
aspectRatio: 1,
|
// ),
|
||||||
child: AppBarIconButton(
|
// title: Text(
|
||||||
icon: SvgPicture.asset(Assets.svg.circleQuestion),
|
// "MonKey",
|
||||||
onPressed: () {
|
// style: STextStyles.navBarTitle(context),
|
||||||
showDialog<dynamic>(
|
// ),
|
||||||
context: context,
|
// actions: [
|
||||||
useSafeArea: false,
|
// AspectRatio(
|
||||||
barrierDismissible: true,
|
// aspectRatio: 1,
|
||||||
builder: (context) {
|
// child: AppBarIconButton(
|
||||||
return Dialog(
|
// icon: SvgPicture.asset(Assets.svg.circleQuestion),
|
||||||
child: Material(
|
// onPressed: () {
|
||||||
borderRadius: BorderRadius.circular(
|
// showDialog<dynamic>(
|
||||||
20,
|
// context: context,
|
||||||
),
|
// useSafeArea: false,
|
||||||
child: Container(
|
// barrierDismissible: true,
|
||||||
height: 200,
|
// builder: (context) {
|
||||||
decoration: BoxDecoration(
|
// return Dialog(
|
||||||
color: Theme.of(context)
|
// child: Material(
|
||||||
.extension<StackColors>()!
|
// borderRadius: BorderRadius.circular(
|
||||||
.popupBG,
|
// 20,
|
||||||
borderRadius: BorderRadius.circular(
|
// ),
|
||||||
20,
|
// child: Container(
|
||||||
),
|
// height: 200,
|
||||||
),
|
// decoration: BoxDecoration(
|
||||||
child: Column(
|
// color: Theme.of(context)
|
||||||
children: [
|
// .extension<StackColors>()!
|
||||||
Center(
|
// .popupBG,
|
||||||
child: Text(
|
// borderRadius: BorderRadius.circular(
|
||||||
"Help",
|
// 20,
|
||||||
style: STextStyles.pageTitleH2(
|
// ),
|
||||||
context),
|
// ),
|
||||||
),
|
// child: Column(
|
||||||
)
|
// children: [
|
||||||
],
|
// Center(
|
||||||
),
|
// child: Text(
|
||||||
),
|
// "Help",
|
||||||
),
|
// style: STextStyles.pageTitleH2(
|
||||||
);
|
// context),
|
||||||
});
|
// ),
|
||||||
}),
|
// )
|
||||||
)
|
// ],
|
||||||
],
|
// ),
|
||||||
),
|
// ),
|
||||||
body: Column(
|
// ),
|
||||||
children: [
|
// );
|
||||||
const Spacer(
|
// });
|
||||||
flex: 1,
|
// }),
|
||||||
),
|
// )
|
||||||
Image.network(
|
// ],
|
||||||
'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512',
|
// ),
|
||||||
),
|
// body: Column(
|
||||||
const Spacer(
|
// children: [
|
||||||
flex: 1,
|
// const Spacer(
|
||||||
),
|
// flex: 1,
|
||||||
Padding(
|
// ),
|
||||||
padding: const EdgeInsets.all(16.0),
|
// if (imageBytes != null)
|
||||||
child: Column(
|
// Container(
|
||||||
children: [
|
// child: SvgPicture.memory(Uint8List.fromList(imageBytes!)),
|
||||||
SecondaryButton(
|
// width: 300,
|
||||||
label: "Download as SVG",
|
// height: 300,
|
||||||
onPressed: () async {
|
// ),
|
||||||
getMonkeySVG(receivingAddress);
|
// const Spacer(
|
||||||
},
|
// flex: 1,
|
||||||
),
|
// ),
|
||||||
const SizedBox(height: 12),
|
// Padding(
|
||||||
SecondaryButton(
|
// padding: const EdgeInsets.all(16.0),
|
||||||
label: "Download as PNG",
|
// child: Column(
|
||||||
onPressed: () {
|
// children: [
|
||||||
getMonkeyPNG(receivingAddress);
|
// SecondaryButton(
|
||||||
},
|
// label: "Download as SVG",
|
||||||
),
|
// onPressed: () async {
|
||||||
],
|
// getMonkeySVG(receivingAddress);
|
||||||
),
|
// },
|
||||||
),
|
// ),
|
||||||
],
|
// const SizedBox(height: 12),
|
||||||
),
|
// SecondaryButton(
|
||||||
),
|
// label: "Download as PNG",
|
||||||
],
|
// onPressed: () {
|
||||||
),
|
// getMonkeyPNG(receivingAddress);
|
||||||
);
|
// },
|
||||||
}
|
// ),
|
||||||
}
|
// ],
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart';
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart';
|
import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart';
|
||||||
|
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
||||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||||
|
import 'package:stackwallet/services/coins/banano/banano_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/manager.dart';
|
import 'package:stackwallet/services/coins/manager.dart';
|
||||||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
|
@ -13,9 +18,10 @@ import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.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/primary_button.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
|
|
||||||
class MonkeyView extends ConsumerStatefulWidget {
|
class MonkeyView extends ConsumerStatefulWidget {
|
||||||
const MonkeyView({
|
const MonkeyView({
|
||||||
|
@ -40,6 +46,123 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
|
|
||||||
String receivingAddress = "";
|
String receivingAddress = "";
|
||||||
|
|
||||||
|
void getMonkeyImage(String address) async {
|
||||||
|
if (address.isEmpty) {
|
||||||
|
//address shouldn't be empty
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final manager = ref.watch(walletsChangeNotifierProvider
|
||||||
|
.select((value) => value.getManager(walletId)));
|
||||||
|
|
||||||
|
final http.Response response = await http
|
||||||
|
.get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final decodedResponse = response.bodyBytes;
|
||||||
|
await (manager.wallet as BananoWallet)
|
||||||
|
.updateMonkeyImageBytes(decodedResponse);
|
||||||
|
} else {
|
||||||
|
throw Exception("Failed to get MonKey");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getMonkeySVG(String address) async {
|
||||||
|
if (address.isEmpty) {
|
||||||
|
//address shouldn't be empty
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final http.Response response = await http
|
||||||
|
.get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final decodedResponse = response.bodyBytes;
|
||||||
|
Directory directory = await getApplicationDocumentsDirectory();
|
||||||
|
late Directory sampleFolder;
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
directory = Directory("/storage/emulated/0/");
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
sampleFolder = Directory(directory!.path);
|
||||||
|
} else if (Platform.isLinux) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isWindows) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isMacOS) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!sampleFolder.existsSync()) {
|
||||||
|
sampleFolder.createSync(recursive: true);
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
// todo: come back to this
|
||||||
|
debugPrint("$e $s");
|
||||||
|
}
|
||||||
|
|
||||||
|
final docPath = sampleFolder.path;
|
||||||
|
final filePath = "$docPath/monkey.svg";
|
||||||
|
|
||||||
|
File imgFile = File(filePath);
|
||||||
|
await imgFile.writeAsBytes(decodedResponse);
|
||||||
|
} else {
|
||||||
|
throw Exception("Failed to get MonKey");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getMonkeyPNG(String address) async {
|
||||||
|
if (address.isEmpty) {
|
||||||
|
//address shouldn't be empty
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final http.Response response = await http.get(Uri.parse(
|
||||||
|
'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
await Permission.storage.request();
|
||||||
|
}
|
||||||
|
|
||||||
|
final decodedResponse = response.bodyBytes;
|
||||||
|
Directory directory = await getApplicationDocumentsDirectory();
|
||||||
|
late Directory sampleFolder;
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
directory = Directory("/storage/emulated/0/");
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
sampleFolder = Directory(directory!.path);
|
||||||
|
} else if (Platform.isLinux) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isWindows) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
} else if (Platform.isMacOS) {
|
||||||
|
sampleFolder = Directory('${directory!.path}Documents');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!sampleFolder.existsSync()) {
|
||||||
|
sampleFolder.createSync(recursive: true);
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
// todo: come back to this
|
||||||
|
debugPrint("$e $s");
|
||||||
|
}
|
||||||
|
|
||||||
|
final docPath = sampleFolder.path;
|
||||||
|
final filePath = "$docPath/monkey.png";
|
||||||
|
|
||||||
|
File imgFile = File(filePath);
|
||||||
|
await imgFile.writeAsBytes(decodedResponse);
|
||||||
|
} else {
|
||||||
|
throw Exception("Failed to get MonKey");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
walletId = widget.walletId;
|
walletId = widget.walletId;
|
||||||
|
@ -66,6 +189,11 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final Coin coin = ref.watch(managerProvider.select((value) => value.coin));
|
final Coin coin = ref.watch(managerProvider.select((value) => value.coin));
|
||||||
|
final manager = ref.watch(walletsChangeNotifierProvider
|
||||||
|
.select((value) => value.getManager(widget.walletId)));
|
||||||
|
|
||||||
|
List<int>? imageBytes;
|
||||||
|
imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes();
|
||||||
|
|
||||||
return Background(
|
return Background(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
@ -123,10 +251,49 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Column(
|
body: ConditionalParent(
|
||||||
|
condition: imageBytes != null,
|
||||||
|
builder: (child) => Column(
|
||||||
|
children: [
|
||||||
|
const Spacer(
|
||||||
|
flex: 1,
|
||||||
|
),
|
||||||
|
if (imageBytes != null)
|
||||||
|
Container(
|
||||||
|
child: SvgPicture.memory(Uint8List.fromList(imageBytes!)),
|
||||||
|
width: 300,
|
||||||
|
height: 300,
|
||||||
|
),
|
||||||
|
const Spacer(
|
||||||
|
flex: 1,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SecondaryButton(
|
||||||
|
label: "Download as SVG",
|
||||||
|
onPressed: () async {
|
||||||
|
getMonkeySVG(receivingAddress);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
SecondaryButton(
|
||||||
|
label: "Download as PNG",
|
||||||
|
onPressed: () {
|
||||||
|
getMonkeyPNG(receivingAddress);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// child,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const Spacer(
|
const Spacer(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
|
@ -167,6 +334,8 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
child: PrimaryButton(
|
child: PrimaryButton(
|
||||||
label: "Fetch MonKey",
|
label: "Fetch MonKey",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
getMonkeyImage(receivingAddress);
|
||||||
|
|
||||||
showDialog<dynamic>(
|
showDialog<dynamic>(
|
||||||
context: context,
|
context: context,
|
||||||
useSafeArea: false,
|
useSafeArea: false,
|
||||||
|
@ -182,12 +351,8 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future<void>.delayed(const Duration(seconds: 2));
|
||||||
|
|
||||||
Navigator.of(context).pushNamed(
|
Navigator.of(context).popUntil(
|
||||||
MonkeyLoadedView.routeName,
|
ModalRoute.withName(WalletView.routeName),
|
||||||
arguments: Tuple2(
|
|
||||||
widget.walletId,
|
|
||||||
widget.managerProvider,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -195,6 +360,7 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,7 +56,6 @@ import 'package:stackwallet/pages/generic/single_field_edit_view.dart';
|
||||||
import 'package:stackwallet/pages/home_view/home_view.dart';
|
import 'package:stackwallet/pages/home_view/home_view.dart';
|
||||||
import 'package:stackwallet/pages/intro_view.dart';
|
import 'package:stackwallet/pages/intro_view.dart';
|
||||||
import 'package:stackwallet/pages/manage_favorites_view/manage_favorites_view.dart';
|
import 'package:stackwallet/pages/manage_favorites_view/manage_favorites_view.dart';
|
||||||
import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart';
|
|
||||||
import 'package:stackwallet/pages/monkey/monkey_view.dart';
|
import 'package:stackwallet/pages/monkey/monkey_view.dart';
|
||||||
import 'package:stackwallet/pages/notification_views/notifications_view.dart';
|
import 'package:stackwallet/pages/notification_views/notifications_view.dart';
|
||||||
import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart';
|
import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart';
|
||||||
|
@ -392,20 +391,20 @@ class RouteGenerator {
|
||||||
}
|
}
|
||||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||||
|
|
||||||
case MonkeyLoadedView.routeName:
|
// case MonkeyLoadedView.routeName:
|
||||||
if (args is Tuple2<String, ChangeNotifierProvider<Manager>>) {
|
// if (args is Tuple2<String, ChangeNotifierProvider<Manager>>) {
|
||||||
return getRoute(
|
// return getRoute(
|
||||||
shouldUseMaterialRoute: useMaterialPageRoute,
|
// shouldUseMaterialRoute: useMaterialPageRoute,
|
||||||
builder: (_) => MonkeyLoadedView(
|
// builder: (_) => MonkeyLoadedView(
|
||||||
walletId: args.item1,
|
// walletId: args.item1,
|
||||||
managerProvider: args.item2,
|
// managerProvider: args.item2,
|
||||||
),
|
// ),
|
||||||
settings: RouteSettings(
|
// settings: RouteSettings(
|
||||||
name: settings.name,
|
// name: settings.name,
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
// return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||||
|
|
||||||
case CoinControlView.routeName:
|
case CoinControlView.routeName:
|
||||||
if (args is Tuple2<String, CoinControlViewType>) {
|
if (args is Tuple2<String, CoinControlViewType>) {
|
||||||
|
|
Loading…
Reference in a new issue