workaround dropdown
This commit is contained in:
parent
5e5e6ee437
commit
c07cc9049b
|
@ -46,7 +46,6 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> connectNode(BuildContext ctx) async {
|
Future<void> connectNode(BuildContext ctx) async {
|
||||||
List<NetworkParams> node = [];
|
|
||||||
HomeProvider _homeProvider = Provider.of<HomeProvider>(ctx, listen: false);
|
HomeProvider _homeProvider = Provider.of<HomeProvider>(ctx, listen: false);
|
||||||
|
|
||||||
// var connectivityResult = await (Connectivity().checkConnectivity());
|
// var connectivityResult = await (Connectivity().checkConnectivity());
|
||||||
|
@ -57,13 +56,14 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
// }
|
// }
|
||||||
_homeProvider.changeMessage("connectionPending".tr(), 0);
|
_homeProvider.changeMessage("connectionPending".tr(), 0);
|
||||||
|
|
||||||
for (String _endpoint in configBox.get('endpoint')) {
|
// configBox.delete('customEndpoint');
|
||||||
final n = NetworkParams();
|
final List<NetworkParams> listEndpoints =
|
||||||
n.name = currencyName;
|
configBox.containsKey('customEndpoint')
|
||||||
n.endpoint = _endpoint;
|
? [getDuniterCustomEndpoint()]
|
||||||
n.ss58 = ss58;
|
: getDuniterBootstrap();
|
||||||
node.add(n);
|
|
||||||
}
|
// final nodes = getDuniterBootstrap();
|
||||||
|
|
||||||
int timeout = 10000;
|
int timeout = 10000;
|
||||||
|
|
||||||
// if (n.endpoint!.startsWith('ws://')) {
|
// if (n.endpoint!.startsWith('ws://')) {
|
||||||
|
@ -93,7 +93,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
|
|
||||||
isLoadingEndpoint = true;
|
isLoadingEndpoint = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
final res = await sdk.api.connectNode(keyring, node).timeout(
|
final res = await sdk.api.connectNode(keyring, listEndpoints).timeout(
|
||||||
Duration(milliseconds: timeout),
|
Duration(milliseconds: timeout),
|
||||||
onTimeout: () => null,
|
onTimeout: () => null,
|
||||||
);
|
);
|
||||||
|
@ -133,6 +133,27 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
log.d(sdk.api.connectedNode?.endpoint);
|
log.d(sdk.api.connectedNode?.endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<NetworkParams> getDuniterBootstrap() {
|
||||||
|
List<NetworkParams> node = [];
|
||||||
|
|
||||||
|
for (String _endpoint in configBox.get('endpoint')) {
|
||||||
|
final n = NetworkParams();
|
||||||
|
n.name = currencyName;
|
||||||
|
n.endpoint = _endpoint;
|
||||||
|
n.ss58 = ss58;
|
||||||
|
node.add(n);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkParams getDuniterCustomEndpoint() {
|
||||||
|
final nodeParams = NetworkParams();
|
||||||
|
nodeParams.name = currencyName;
|
||||||
|
nodeParams.endpoint = configBox.get('customEndpoint');
|
||||||
|
nodeParams.ss58 = ss58;
|
||||||
|
return nodeParams;
|
||||||
|
}
|
||||||
|
|
||||||
Future<String> importAccount(
|
Future<String> importAccount(
|
||||||
{String mnemonic = '',
|
{String mnemonic = '',
|
||||||
bool fromMnemonic = false,
|
bool fromMnemonic = false,
|
||||||
|
|
|
@ -5,7 +5,9 @@ import 'package:gecko/providers/my_wallets.dart';
|
||||||
import 'package:gecko/providers/settings_provider.dart';
|
import 'package:gecko/providers/settings_provider.dart';
|
||||||
import 'package:gecko/providers/substrate_sdk.dart';
|
import 'package:gecko/providers/substrate_sdk.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
|
import 'package:polkawallet_sdk/api/types/networkParams.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class SettingsScreen extends StatelessWidget {
|
class SettingsScreen extends StatelessWidget {
|
||||||
|
@ -14,29 +16,21 @@ class SettingsScreen extends StatelessWidget {
|
||||||
SettingsScreen({Key? key}) : super(key: key);
|
SettingsScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
// Initial Selected Value
|
// Initial Selected Value
|
||||||
String dropdownvalue = 'Item 1';
|
String? selectedDuniterEndpoint;
|
||||||
|
|
||||||
// List of items in our dropdown menu
|
|
||||||
var items = [
|
|
||||||
'Item 1',
|
|
||||||
'Item 2',
|
|
||||||
'Item 3',
|
|
||||||
'Item 4',
|
|
||||||
'Item 5',
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||||
TextEditingController _endpointController = TextEditingController(
|
|
||||||
text: _sub.sdk.api.connectedNode?.endpoint ??
|
|
||||||
configBox.get('endpoint').first);
|
|
||||||
|
|
||||||
const double buttonHigh = 50;
|
const double buttonHigh = 50;
|
||||||
const double buttonWidth = 240;
|
const double buttonWidth = 240;
|
||||||
const double fontSize = 16;
|
const double fontSize = 16;
|
||||||
|
|
||||||
|
// List of items in our dropdown menu
|
||||||
|
var duniterBootstrapNodes = _sub.getDuniterBootstrap();
|
||||||
|
selectedDuniterEndpoint = _sub.getConnectedEndpoint();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -47,23 +41,7 @@ class SettingsScreen extends StatelessWidget {
|
||||||
)),
|
)),
|
||||||
body: Column(children: <Widget>[
|
body: Column(children: <Widget>[
|
||||||
const SizedBox(height: 60),
|
const SizedBox(height: 60),
|
||||||
Consumer<SettingsProvider>(builder: (context, _set, _) {
|
|
||||||
return DropdownButton(
|
|
||||||
value: dropdownvalue,
|
|
||||||
icon: const Icon(Icons.keyboard_arrow_down),
|
|
||||||
items: items.map((String items) {
|
|
||||||
return DropdownMenuItem(
|
|
||||||
value: items,
|
|
||||||
child: Text(items),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (String? newValue) {
|
|
||||||
log.d('coucoucoucouc');
|
|
||||||
dropdownvalue = newValue!;
|
|
||||||
_set.reload();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
||||||
log.d(_sub.sdk.api.connectedNode?.endpoint);
|
log.d(_sub.sdk.api.connectedNode?.endpoint);
|
||||||
|
@ -76,26 +54,49 @@ class SettingsScreen extends StatelessWidget {
|
||||||
? Icons.check
|
? Icons.check
|
||||||
: Icons.close),
|
: Icons.close),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
SizedBox(
|
Consumer<SettingsProvider>(builder: (context, _set, _) {
|
||||||
width: 200,
|
return DropdownButtonHideUnderline(
|
||||||
height: 50,
|
child: DropdownButton(
|
||||||
child: TextField(
|
//TODO
|
||||||
controller: _endpointController,
|
value: selectedDuniterEndpoint ??
|
||||||
autocorrect: false,
|
duniterBootstrapNodes.first.endpoint,
|
||||||
),
|
icon: const Icon(Icons.keyboard_arrow_down),
|
||||||
|
items: duniterBootstrapNodes
|
||||||
|
.map((NetworkParams _endpointParams) {
|
||||||
|
return DropdownMenuItem(
|
||||||
|
value: _endpointParams.endpoint,
|
||||||
|
child: Text(_endpointParams.endpoint!),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? _newEndpoint) {
|
||||||
|
log.d(_newEndpoint!);
|
||||||
|
selectedDuniterEndpoint = _newEndpoint;
|
||||||
|
_set.reload();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
const Spacer(flex: 5),
|
const Spacer(flex: 5),
|
||||||
_sub.isLoadingEndpoint
|
_sub.isLoadingEndpoint
|
||||||
? CircularProgressIndicator(color: orangeC)
|
? CircularProgressIndicator(color: orangeC)
|
||||||
: IconButton(
|
: Consumer<SettingsProvider>(builder: (context, _set, _) {
|
||||||
|
return IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.send,
|
Icons.send,
|
||||||
color: orangeC,
|
color: selectedDuniterEndpoint !=
|
||||||
|
_sub.getConnectedEndpoint()
|
||||||
|
? orangeC
|
||||||
|
: Colors.grey[500],
|
||||||
size: 40,
|
size: 40,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: selectedDuniterEndpoint !=
|
||||||
configBox.put('endpoint', [_endpointController.text]);
|
_sub.getConnectedEndpoint()
|
||||||
|
? () async {
|
||||||
|
configBox.put('customEndpoint',
|
||||||
|
selectedDuniterEndpoint);
|
||||||
await _sub.connectNode(context);
|
await _sub.connectNode(context);
|
||||||
|
}
|
||||||
|
: null);
|
||||||
}),
|
}),
|
||||||
const Spacer(flex: 8),
|
const Spacer(flex: 8),
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -309,6 +309,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.0"
|
||||||
|
dropdown_button2:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: dropdown_button2
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.6.3"
|
||||||
durt:
|
durt:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -74,6 +74,7 @@ dependencies:
|
||||||
image_cropper: ^2.0.3
|
image_cropper: ^2.0.3
|
||||||
easy_localization: ^3.0.1
|
easy_localization: ^3.0.1
|
||||||
flutter_markdown: ^0.6.10+2
|
flutter_markdown: ^0.6.10+2
|
||||||
|
dropdown_button2: ^1.6.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
# flutter_launcher_icons: ^0.9.2
|
# flutter_launcher_icons: ^0.9.2
|
||||||
|
|
Loading…
Reference in New Issue