ConanServerManager/lib/serversettings.dart
2023-11-05 00:03:15 -07:00

165 lines
4.6 KiB
Dart

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,
))
],
)
],
)),
),
),
);
}
}