3
0
Fork 0
trifid_mobile/lib/screens/siteConfig/UnsafeRouteScreen.dart

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
4.1 KiB
Dart
Raw Normal View History

2020-07-27 20:43:58 +00:00
import 'package:flutter/cupertino.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:mobile_nebula/components/CIDRFormField.dart';
import 'package:mobile_nebula/components/FormPage.dart';
import 'package:mobile_nebula/components/IPFormField.dart';
import 'package:mobile_nebula/components/config/ConfigItem.dart';
import 'package:mobile_nebula/components/config/ConfigSection.dart';
import 'package:mobile_nebula/models/CIDR.dart';
import 'package:mobile_nebula/models/UnsafeRoute.dart';
import 'package:mobile_nebula/services/utils.dart';
class UnsafeRouteScreen extends StatefulWidget {
const UnsafeRouteScreen({
Key? key,
required this.route,
required this.onSave,
this.onDelete,
}) : super(key: key);
2020-07-27 20:43:58 +00:00
final UnsafeRoute route;
final ValueChanged<UnsafeRoute> onSave;
final Function? onDelete;
2020-07-27 20:43:58 +00:00
@override
_UnsafeRouteScreenState createState() => _UnsafeRouteScreenState();
}
class _UnsafeRouteScreenState extends State<UnsafeRouteScreen> {
late UnsafeRoute route;
2020-07-27 20:43:58 +00:00
bool changed = false;
FocusNode routeFocus = FocusNode();
FocusNode viaFocus = FocusNode();
FocusNode mtuFocus = FocusNode();
@override
void initState() {
route = widget.route;
super.initState();
}
@override
Widget build(BuildContext context) {
var routeCIDR = route.route == null ? CIDR() : CIDR.fromString(route.route!);
2020-07-27 20:43:58 +00:00
return FormPage(
title: widget.onDelete == null ? 'New Unsafe Route' : 'Edit Unsafe Route',
changed: changed,
onSave: _onSave,
child: Column(children: [
ConfigSection(children: <Widget>[
ConfigItem(
label: Text('Route'),
content: CIDRFormField(
initialValue: routeCIDR,
textInputAction: TextInputAction.next,
focusNode: routeFocus,
nextFocusNode: viaFocus,
onSaved: (v) {
route.route = v.toString();
})),
ConfigItem(
label: Text('Via'),
content: IPFormField(
initialValue: route.via ?? '',
2020-07-27 20:43:58 +00:00
ipOnly: true,
help: 'nebula ip',
textAlign: TextAlign.end,
crossAxisAlignment: CrossAxisAlignment.end,
textInputAction: TextInputAction.next,
focusNode: viaFocus,
nextFocusNode: mtuFocus,
onSaved: (v) {
if (v != null) {
route.via = v;
}
2020-07-27 20:43:58 +00:00
})),
//TODO: Android doesn't appear to support route based MTU, figure this out
// ConfigItem(
// label: Text('MTU'),
// content: PlatformTextFormField(
// placeholder: "",
// validator: mtuValidator(false),
// keyboardType: TextInputType.number,
// inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
// initialValue: route?.mtu.toString(),
// textAlign: TextAlign.end,
// textInputAction: TextInputAction.done,
// focusNode: mtuFocus,
// onSaved: (v) {
// route.mtu = int.tryParse(v);
// })),
]),
widget.onDelete != null
? Padding(
padding: EdgeInsets.only(top: 50, bottom: 10, left: 10, right: 10),
child: SizedBox(
width: double.infinity,
2022-07-27 16:38:02 +00:00
child: PlatformElevatedButton(
2020-07-27 20:43:58 +00:00
child: Text('Delete'),
color: CupertinoColors.systemRed.resolveFrom(context),
onPressed: () => Utils.confirmDelete(context, 'Delete unsafe route?', () {
Navigator.of(context).pop();
widget.onDelete!();
2020-07-27 20:43:58 +00:00
}),
)))
: Container()
]));
}
_onSave() {
Navigator.pop(context);
widget.onSave(route);
2020-07-27 20:43:58 +00:00
}
}