Skip to content

Commit

Permalink
✨ Choose es server
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Jul 4, 2023
1 parent b5aa5c3 commit 126d1f7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/basic/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@ class Methods {
},
);
}

Future<String> getProServerName() async {
return await _invoke("get_pro_server_name", "");
}

Future setProServerName(String serverName) async {
return await _invoke("set_pro_server_name", serverName);
}
}

class _Response {
Expand Down
60 changes: 60 additions & 0 deletions lib/screens/pro_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,68 @@ class _ProScreenState extends State<ProScreen> {
},
),
const Divider(),
const ProServerNameWidget(),
const Divider(),
const Divider(),
],
),
);
}
}


class ProServerNameWidget extends StatefulWidget {
const ProServerNameWidget({Key? key}) : super(key: key);

@override
State<StatefulWidget> createState() => _ProServerNameWidgetState();
}

class _ProServerNameWidgetState extends State<ProServerNameWidget> {
String _serverName = "";

@override
void initState() {
methods.getProServerName().then((value) {
setState(() {
_serverName = value;
});
});
super.initState();
}

@override
Widget build(BuildContext context) {
return ListTile(
title: const Text("发电方式"),
subtitle: Text(_loadServerName()),
onTap: () async {
final serverName = await chooseMapDialog(
context,
title: "选择发电方式",
values: {
"风力发电": "HK",
"水力发电": "US",
},
);
if (serverName != null && serverName.isNotEmpty) {
await methods.setProServerName(serverName);
setState(() {
_serverName = serverName;
});
}
},
);
}

String _loadServerName() {
switch (_serverName) {
case "HK":
return "风力发电";
case "US":
return "水力发电";
default:
return "";
}
}
}

0 comments on commit 126d1f7

Please sign in to comment.