ConanServerManager/lib/pages/autorestart.dart

131 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:libac_dart/utils/TimeUtils.dart';
import 'package:servermanager/structs/autorestarts.dart';
import 'package:servermanager/structs/settings.dart';
class AutoRestartPage extends StatefulWidget {
AutoRestartPage({super.key});
@override
AutoRestartState createState() => AutoRestartState();
}
class AutoRestartState extends State<AutoRestartPage> {
Settings settings = Settings();
bool firstDisplay = true;
bool enabled = false;
Time time = Time(hours: 0, minutes: 0, seconds: 0);
@override
Widget build(BuildContext context) {
if (firstDisplay) {
var args =
ModalRoute.of(context)!.settings.arguments as AutomaticRestartInfo;
enabled = args.enabled;
time = args.time.copy();
firstDisplay = false;
}
return Scaffold(
appBar: AppBar(
title: Text("Automatic Restart"),
backgroundColor: Color.fromARGB(255, 100, 0, 0),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(children: [
SwitchListTile(
value: enabled,
onChanged: (val) {
setState(() {
enabled = !enabled;
});
},
title: Text("Enabled"),
),
Row(
children: [
SizedBox(
width: 256,
child: ListTile(
title: Text("Hours"),
subtitle: Text("${time.hours}"),
),
),
Expanded(
child: Slider(
max: 24,
min: 0,
value: time.hours.toDouble(),
onChanged: (value) {
setState(() {
time.hours = value.toInt();
});
},
),
)
],
),
Row(
children: [
SizedBox(
width: 256,
child: ListTile(
title: Text("Minutes"),
subtitle: Text("${time.minutes}"),
),
),
Expanded(
child: Slider(
max: 60,
min: 0,
value: time.minutes.toDouble(),
onChanged: (value) {
setState(() {
time.minutes = value.toInt();
});
},
),
)
],
),
Row(
children: [
SizedBox(
width: 256,
child: ListTile(
title: Text("Seconds"),
subtitle: Text("${time.seconds}"),
),
),
Expanded(
child: Slider(
max: 60,
min: 0,
value: time.seconds.toDouble(),
onChanged: (value) {
setState(() {
time.seconds = value.toInt();
});
},
),
)
],
),
Row(
children: [
ElevatedButton(
onPressed: () {
Navigator.pop(context,
AutomaticRestartInfo(enabled: enabled, time: time));
},
child: Text("Submit"))
],
)
]),
)),
);
}
}