Add state machine
This commit is contained in:
parent
1bd6da4f1b
commit
fee32c7701
7 changed files with 312 additions and 23 deletions
165
lib/serversettings.dart
Normal file
165
lib/serversettings.dart
Normal file
|
@ -0,0 +1,165 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'serversettings.g.dart';
|
||||
|
||||
@HiveType(typeId: 5)
|
||||
class ServerSettings {
|
||||
@HiveField(0, defaultValue: "Password01234")
|
||||
final String RconPassword;
|
||||
|
||||
@HiveField(1, defaultValue: 7779)
|
||||
final int RconPort;
|
||||
|
||||
@HiveField(2, defaultValue: 7780)
|
||||
final int GamePort;
|
||||
|
||||
@HiveField(3, defaultValue: 7782)
|
||||
final int QueryPort;
|
||||
|
||||
const ServerSettings(
|
||||
{required this.RconPassword,
|
||||
required this.RconPort,
|
||||
required this.GamePort,
|
||||
required this.QueryPort});
|
||||
}
|
||||
|
||||
class ServerSettingsPage extends StatefulWidget {
|
||||
ServerSettingsPage({super.key});
|
||||
|
||||
@override
|
||||
ServerSettingsState createState() => ServerSettingsState();
|
||||
}
|
||||
|
||||
class ServerSettingsState extends State<ServerSettingsPage> {
|
||||
bool firstRun = true;
|
||||
String pass = "";
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
int rconPort = 0;
|
||||
int gPort = 0;
|
||||
int qPort = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (firstRun) {
|
||||
var args = ModalRoute.of(context)!.settings.arguments as ServerSettings;
|
||||
|
||||
passwordController.text = args.RconPassword;
|
||||
rconPort = args.RconPort;
|
||||
gPort = args.GamePort;
|
||||
qPort = args.QueryPort;
|
||||
|
||||
firstRun = false;
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Server Settings"),
|
||||
backgroundColor: Color.fromARGB(255, 100, 0, 0),
|
||||
),
|
||||
body: WillPopScope(
|
||||
onWillPop: () async {
|
||||
Navigator.pop(
|
||||
context,
|
||||
ServerSettings(
|
||||
RconPassword: passwordController.text,
|
||||
RconPort: rconPort,
|
||||
GamePort: gPort,
|
||||
QueryPort: qPort));
|
||||
return true;
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(title: Text("Rcon Password")),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: passwordController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8))),
|
||||
))
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Rcon Port"),
|
||||
subtitle: Text("${rconPort}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: rconPort.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
rconPort = value.toInt();
|
||||
});
|
||||
},
|
||||
min: 5000,
|
||||
max: 8000,
|
||||
))
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Game Port"),
|
||||
subtitle: Text("${gPort}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: gPort.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
gPort = value.toInt();
|
||||
});
|
||||
},
|
||||
min: 5000,
|
||||
max: 8000,
|
||||
))
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Query Port"),
|
||||
subtitle: Text("${qPort}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: qPort.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
qPort = value.toInt();
|
||||
});
|
||||
},
|
||||
min: 5000,
|
||||
max: 8000,
|
||||
))
|
||||
],
|
||||
)
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue