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