2022-12-08 08:17:36 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2022-12-08 08:17:36 +01:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-11-23 04:11:45 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-08-23 02:13:54 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/search.dart';
|
2022-06-12 18:03:17 +02:00
|
|
|
import 'package:gecko/screens/common_elements.dart';
|
2021-11-23 04:11:45 +01:00
|
|
|
import 'package:gecko/screens/search_result.dart';
|
2022-12-08 08:17:36 +01:00
|
|
|
import 'package:gecko/screens/wallet_view.dart';
|
2021-11-23 04:11:45 +01:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2022-12-08 08:17:36 +01:00
|
|
|
class SearchScreen extends StatefulWidget {
|
2021-12-23 12:36:09 +01:00
|
|
|
const SearchScreen({Key? key}) : super(key: key);
|
2021-11-23 04:11:45 +01:00
|
|
|
|
2022-12-08 08:17:36 +01:00
|
|
|
@override
|
|
|
|
State<SearchScreen> createState() => _SearchScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
|
|
bool canPasteAddress = false;
|
|
|
|
String pastedAddress = '';
|
|
|
|
|
|
|
|
Future getClipBoard() async {
|
|
|
|
final clipboard = await Clipboard.getData('text/plain');
|
|
|
|
pastedAddress = clipboard?.text ?? '';
|
|
|
|
canPasteAddress = isAddress(pastedAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
await getClipBoard();
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2021-11-23 04:11:45 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final searchProvider = Provider.of<SearchProvider>(context);
|
2022-12-02 10:23:21 +01:00
|
|
|
final screenHeight = MediaQuery.of(context).size.height;
|
2021-11-23 04:11:45 +01:00
|
|
|
|
2022-12-08 08:17:36 +01:00
|
|
|
final canValidate = searchProvider.searchController.text.length >= 2;
|
|
|
|
// final canPasteAddress = false;
|
|
|
|
|
2021-11-23 04:11:45 +01:00
|
|
|
return WillPopScope(
|
2022-06-12 19:43:13 +02:00
|
|
|
onWillPop: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
searchProvider.searchController.text = '';
|
2022-06-12 19:43:13 +02:00
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 1,
|
|
|
|
toolbarHeight: 60 * ratio,
|
2022-06-18 03:01:22 +02:00
|
|
|
title: SizedBox(
|
2022-06-12 19:43:13 +02:00
|
|
|
height: 22,
|
2022-06-18 03:01:22 +02:00
|
|
|
child: Text('search'.tr()),
|
2021-11-23 04:11:45 +01:00
|
|
|
),
|
2022-06-12 19:43:13 +02:00
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
searchProvider.searchController.text = '';
|
2022-06-12 19:43:13 +02:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
body: SafeArea(
|
|
|
|
child: Stack(children: [
|
|
|
|
Column(children: <Widget>[
|
2021-11-23 04:11:45 +01:00
|
|
|
SizedBox(height: isTall ? 200 : 100),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 17),
|
|
|
|
child: TextField(
|
2022-12-05 02:25:49 +01:00
|
|
|
onSubmitted: searchProvider.searchController.text.length >= 2
|
|
|
|
? (_) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return const SearchResultScreen();
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
: (value) {},
|
|
|
|
textInputAction: TextInputAction.search,
|
2022-08-23 02:13:54 +02:00
|
|
|
key: keySearchField,
|
2022-08-06 02:22:41 +02:00
|
|
|
controller: searchProvider.searchController,
|
2021-11-23 04:11:45 +01:00
|
|
|
autofocus: true,
|
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.left,
|
2022-12-08 08:17:36 +01:00
|
|
|
onChanged: (v) async => {
|
|
|
|
await getClipBoard(),
|
2022-12-09 03:36:46 +01:00
|
|
|
// setState(() {}),
|
2022-12-08 08:17:36 +01:00
|
|
|
searchProvider.reload()
|
|
|
|
},
|
2021-11-23 04:11:45 +01:00
|
|
|
decoration: InputDecoration(
|
|
|
|
filled: true,
|
|
|
|
fillColor: Colors.white,
|
|
|
|
prefixIconConstraints: const BoxConstraints(
|
|
|
|
minHeight: 32,
|
|
|
|
),
|
2022-12-09 03:36:46 +01:00
|
|
|
suffixIcon: searchProvider.searchController.text == ''
|
|
|
|
? null
|
|
|
|
: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 17),
|
|
|
|
child: IconButton(
|
|
|
|
onPressed: (() async => {
|
|
|
|
searchProvider.searchController.text = '',
|
|
|
|
await getClipBoard(),
|
|
|
|
searchProvider.reload(),
|
|
|
|
}),
|
|
|
|
icon: Icon(
|
|
|
|
Icons.close,
|
|
|
|
color: Colors.grey[600],
|
|
|
|
size: 30,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-11-23 04:11:45 +01:00
|
|
|
prefixIcon: const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 17),
|
|
|
|
child: Image(
|
|
|
|
image: AssetImage('assets/loupe-noire.png'),
|
|
|
|
height: 35),
|
|
|
|
),
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderSide:
|
2021-12-23 12:36:09 +01:00
|
|
|
BorderSide(color: Colors.grey[500]!, width: 2),
|
2021-11-23 04:11:45 +01:00
|
|
|
borderRadius: BorderRadius.circular(8)),
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide:
|
2021-12-23 12:36:09 +01:00
|
|
|
BorderSide(color: Colors.grey[500]!, width: 2.5),
|
2021-11-23 04:11:45 +01:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
contentPadding: const EdgeInsets.all(20),
|
|
|
|
),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(flex: 1),
|
|
|
|
SizedBox(
|
2022-12-05 02:25:49 +01:00
|
|
|
width: 320,
|
|
|
|
height: 90,
|
2021-11-23 04:11:45 +01:00
|
|
|
child: ElevatedButton(
|
2022-08-23 02:13:54 +02:00
|
|
|
key: keyConfirmSearch,
|
2021-11-23 04:11:45 +01:00
|
|
|
style: ElevatedButton.styleFrom(
|
2022-09-05 08:12:24 +02:00
|
|
|
foregroundColor: Colors.white, elevation: 4,
|
|
|
|
backgroundColor: orangeC, // foreground
|
2021-11-23 04:11:45 +01:00
|
|
|
),
|
2022-12-08 08:17:36 +01:00
|
|
|
onPressed: canValidate
|
2021-11-23 04:11:45 +01:00
|
|
|
? () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return const SearchResultScreen();
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2022-12-08 08:17:36 +01:00
|
|
|
: canPasteAddress
|
|
|
|
? () async {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return WalletViewScreen(
|
|
|
|
address: pastedAddress, username: '');
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
: null,
|
2022-06-18 03:01:22 +02:00
|
|
|
child: Text(
|
2022-12-08 08:17:36 +01:00
|
|
|
canValidate
|
|
|
|
? 'search'.tr()
|
|
|
|
: canPasteAddress
|
|
|
|
? 'pasteAddress'.tr()
|
|
|
|
: 'search'.tr(),
|
2022-12-05 02:25:49 +01:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 03:01:22 +02:00
|
|
|
style: const TextStyle(
|
2022-12-05 02:25:49 +01:00
|
|
|
fontSize: 21, fontWeight: FontWeight.w600),
|
2021-11-23 04:11:45 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2021-12-23 21:44:24 +01:00
|
|
|
Spacer(flex: screenHeight <= 800 ? 1 : 2),
|
2021-11-23 04:11:45 +01:00
|
|
|
]),
|
2022-06-12 19:43:13 +02:00
|
|
|
CommonElements().offlineInfo(context),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-11-23 04:11:45 +01:00
|
|
|
}
|
|
|
|
}
|