import 'dart:math'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:hive/hive.dart'; import 'package:servermanager/settings.dart'; part 'autorestart.g.dart'; @HiveType(typeId: 3) class AutomaticRestartInfo { @HiveField(0, defaultValue: 0) final int hours; @HiveField(1, defaultValue: 0) final int minutes; @HiveField(2, defaultValue: 0) final int seconds; @HiveField(3, defaultValue: false) final bool enabled; const AutomaticRestartInfo( {this.hours = 0, this.minutes = 0, this.seconds = 0, this.enabled = false}); } class AutoRestartPage extends StatefulWidget { AutoRestartPage({super.key}); @override AutoRestartState createState() => AutoRestartState(); } class AutoRestartState extends State { Settings settings = Settings(); bool firstDisplay = true; bool enabled = false; int seconds = 0; int minutes = 0; int hours = 0; @override Widget build(BuildContext context) { if (firstDisplay) { var args = ModalRoute.of(context)!.settings.arguments as AutomaticRestartInfo; enabled = args.enabled; seconds = args.seconds; minutes = args.minutes; hours = args.hours; firstDisplay = false; } return Scaffold( appBar: AppBar( title: Text("Automatic Restart"), backgroundColor: Color.fromARGB(255, 100, 0, 0), ), body: WillPopScope( onWillPop: () async { Navigator.pop( context, AutomaticRestartInfo( enabled: enabled, hours: hours, minutes: minutes, seconds: seconds)); return true; }, child: 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("${hours}"), ), ), Expanded( child: Slider( max: 24, min: 0, value: hours.toDouble(), onChanged: (value) { setState(() { hours = value.toInt(); }); }, ), ) ], ), Row( children: [ SizedBox( width: 256, child: ListTile( title: Text("Minutes"), subtitle: Text("${minutes}"), ), ), Expanded( child: Slider( max: 60, min: 0, value: minutes.toDouble(), onChanged: (value) { setState(() { minutes = value.toInt(); }); }, ), ) ], ), Row( children: [ SizedBox( width: 256, child: ListTile( title: Text("Seconds"), subtitle: Text("${seconds}"), ), ), Expanded( child: Slider( max: 60, min: 0, value: seconds.toDouble(), onChanged: (value) { setState(() { seconds = value.toInt(); }); }, ), ) ], ) ]), )), ), ); } }