fix: listen clipboard changes in search screen
This commit is contained in:
parent
de341c3a07
commit
f1208846fc
|
@ -113,7 +113,10 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
|
||||
Future<bool> isAddress(String address) async {
|
||||
final sub = Provider.of<SubstrateSdk>(homeContext, listen: false);
|
||||
return await sub.sdk.api.account.checkAddressFormat(address, sub.initSs58) ??
|
||||
return await sub.sdk.api.account
|
||||
.checkAddressFormat(address, sub.initSs58)
|
||||
.timeout(const Duration(milliseconds: 300))
|
||||
.onError((_, __) => false) ??
|
||||
false;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,27 +23,47 @@ class SearchScreen extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _SearchScreenState extends State<SearchScreen> {
|
||||
bool canPasteAddress = false;
|
||||
String pastedAddress = '';
|
||||
Timer? debounce;
|
||||
final int debouneTime = 50;
|
||||
bool canPasteAddress = false;
|
||||
String pastedAddress = '';
|
||||
Timer? clipboardPollingTimer;
|
||||
|
||||
Future getClipBoard() async {
|
||||
void getClipBoard() {
|
||||
final searchProvider = Provider.of<SearchProvider>(context, listen: false);
|
||||
final clipboard = await Clipboard.getData('text/plain');
|
||||
pastedAddress = clipboard?.text ?? '';
|
||||
canPasteAddress = await isAddress(pastedAddress);
|
||||
searchProvider.reload();
|
||||
|
||||
// Function to check clipboard and update if necessary
|
||||
Future<void> checkAndUpdateClipboard() async {
|
||||
var clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (clipboardData?.text != null && clipboardData!.text != pastedAddress) {
|
||||
pastedAddress = clipboardData.text ?? '';
|
||||
canPasteAddress = await isAddress(pastedAddress);
|
||||
searchProvider.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// Check clipboard immediately
|
||||
checkAndUpdateClipboard();
|
||||
|
||||
// Set up the periodic clipboard checking
|
||||
clipboardPollingTimer =
|
||||
Timer.periodic(const Duration(milliseconds: 500), (_) async {
|
||||
await checkAndUpdateClipboard();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await getClipBoard();
|
||||
});
|
||||
getClipBoard();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
clipboardPollingTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final searchProvider = Provider.of<SearchProvider>(context);
|
||||
|
@ -82,7 +102,6 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
onChanged: (v) => {
|
||||
if (debounce?.isActive ?? false) {debounce!.cancel()},
|
||||
debounce = Timer(Duration(milliseconds: debouneTime), () {
|
||||
getClipBoard();
|
||||
searchProvider.reload();
|
||||
})
|
||||
},
|
||||
|
@ -99,7 +118,6 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
child: IconButton(
|
||||
onPressed: (() async => {
|
||||
searchProvider.searchController.text = '',
|
||||
await getClipBoard(),
|
||||
searchProvider.reload(),
|
||||
}),
|
||||
icon: Icon(
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'package:gecko/models/scale_functions.dart';
|
|||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/widgets/commons/animated_text.dart';
|
||||
import 'package:gecko/widgets/commons/loading.dart';
|
||||
import 'package:gecko/widgets/name_by_address.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Pay with G1.
|
|||
# pub.dev using `pub publish`. This is preferred for private packages.
|
||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 0.1.4+66
|
||||
version: 0.1.4+68
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
|
Loading…
Reference in New Issue