mobile_nebula/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';
Add DangerButton component (#219) This pulls out a component that we can use for "dangerous" operations like deleting, and styles it in one place. It also starts to move us slowly towards Material 3, with the rounded corners on these buttons in Android. Android: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="425" alt="Android Studio 2025-01-15 14 16 36" src="https://github.com/user-attachments/assets/4823e551-6a40-48dd-9bc1-3004699b90ea" />|<img width="417" alt="Android Studio 2025-01-15 14 16 47" src="https://github.com/user-attachments/assets/df5461fd-586e-47bb-99b9-0212e63f0454" />|<img width="413" alt="Android Studio 2025-01-15 14 15 59" src="https://github.com/user-attachments/assets/d88a6225-b71a-4886-8387-e35811a3a6ec" />|<img width="418" alt="Android Studio 2025-01-15 14 16 15" src="https://github.com/user-attachments/assets/d4f23b1c-7003-4a00-b865-4a123d8fe3e9" />| iOS: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="437" alt="Simulator 2025-01-15 15 56 26" src="https://github.com/user-attachments/assets/87c4eed3-6d07-4858-8ad8-d8c011538154" />|<img width="445" alt="Simulator 2025-01-15 15 56 36" src="https://github.com/user-attachments/assets/9dc5b174-7bc7-48ec-a3c0-61633168c31a" />|<img width="439" alt="Simulator 2025-01-15 16 05 23" src="https://github.com/user-attachments/assets/31dc9ab6-8a3c-49c7-892d-627f16e2a8cd" />|<img width="444" alt="Simulator 2025-01-15 16 05 37" src="https://github.com/user-attachments/assets/979280d6-e1f4-4d57-a86a-10bb4def729a" />|
2025-01-16 13:16:23 +00:00
import 'package:mobile_nebula/components/DangerButton.dart';
2020-07-27 20:43:58 +00:00
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,
Add DangerButton component (#219) This pulls out a component that we can use for "dangerous" operations like deleting, and styles it in one place. It also starts to move us slowly towards Material 3, with the rounded corners on these buttons in Android. Android: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="425" alt="Android Studio 2025-01-15 14 16 36" src="https://github.com/user-attachments/assets/4823e551-6a40-48dd-9bc1-3004699b90ea" />|<img width="417" alt="Android Studio 2025-01-15 14 16 47" src="https://github.com/user-attachments/assets/df5461fd-586e-47bb-99b9-0212e63f0454" />|<img width="413" alt="Android Studio 2025-01-15 14 15 59" src="https://github.com/user-attachments/assets/d88a6225-b71a-4886-8387-e35811a3a6ec" />|<img width="418" alt="Android Studio 2025-01-15 14 16 15" src="https://github.com/user-attachments/assets/d4f23b1c-7003-4a00-b865-4a123d8fe3e9" />| iOS: |Before Light|Before Dark|After Light|After Dark| |---|---|---|---| |<img width="437" alt="Simulator 2025-01-15 15 56 26" src="https://github.com/user-attachments/assets/87c4eed3-6d07-4858-8ad8-d8c011538154" />|<img width="445" alt="Simulator 2025-01-15 15 56 36" src="https://github.com/user-attachments/assets/9dc5b174-7bc7-48ec-a3c0-61633168c31a" />|<img width="439" alt="Simulator 2025-01-15 16 05 23" src="https://github.com/user-attachments/assets/31dc9ab6-8a3c-49c7-892d-627f16e2a8cd" />|<img width="444" alt="Simulator 2025-01-15 16 05 37" src="https://github.com/user-attachments/assets/979280d6-e1f4-4d57-a86a-10bb4def729a" />|
2025-01-16 13:16:23 +00:00
child: DangerButton(
2020-07-27 20:43:58 +00:00
child: Text('Delete'),
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
}
}