2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-25 20:35:04 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2022-12-21 17:18:00 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-04-25 20:35:04 +00:00
|
|
|
import 'package:stackwallet/networking/http.dart';
|
|
|
|
import 'package:stackwallet/services/tor_service.dart';
|
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
2022-12-21 17:18:00 +00:00
|
|
|
|
|
|
|
class PayNymBot extends StatelessWidget {
|
|
|
|
const PayNymBot({
|
|
|
|
Key? key,
|
|
|
|
required this.paymentCodeString,
|
|
|
|
this.size = 60.0,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String paymentCodeString;
|
|
|
|
final double size;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(size / 2),
|
2022-12-21 19:46:50 +00:00
|
|
|
child: SizedBox(
|
|
|
|
width: size,
|
|
|
|
height: size,
|
2024-04-25 20:35:04 +00:00
|
|
|
child: FutureBuilder<Uint8List>(
|
|
|
|
future: _fetchImage(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return Image.memory(snapshot.data!);
|
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
return const Center(child: Icon(Icons.error));
|
|
|
|
} else {
|
|
|
|
return const Center(); // TODO [prio=low]: Make better loading indicator.
|
|
|
|
}
|
|
|
|
},
|
2022-12-21 19:46:50 +00:00
|
|
|
),
|
2022-12-21 17:18:00 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-04-25 20:35:04 +00:00
|
|
|
|
|
|
|
Future<Uint8List> _fetchImage() async {
|
|
|
|
final HTTP client = HTTP();
|
|
|
|
final Uri uri = Uri.parse("https://paynym.is/$paymentCodeString/avatar");
|
|
|
|
|
|
|
|
final response = await client.get(
|
|
|
|
url: uri,
|
|
|
|
proxyInfo: Prefs.instance.useTor
|
|
|
|
? TorService.sharedInstance.getProxyInfo()
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
return Uint8List.fromList(response.bodyBytes);
|
|
|
|
} else {
|
|
|
|
throw Exception('Failed to load image');
|
|
|
|
}
|
|
|
|
}
|
2022-12-21 17:18:00 +00:00
|
|
|
}
|