Skip to content

Commit

Permalink
flutter fmt lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
jasikpark committed Feb 13, 2025
1 parent b2ebe02 commit 6c1042a
Show file tree
Hide file tree
Showing 56 changed files with 2,405 additions and 2,132 deletions.
58 changes: 32 additions & 26 deletions lib/components/CIDRField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ class _CIDRFieldState extends State<CIDRField> {
var textStyle = CupertinoTheme.of(context).textTheme.textStyle;

return Container(
child: Row(children: <Widget>[
Expanded(
child: Padding(
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.fromLTRB(6, 6, 2, 6),
child: IPField(
help: widget.ipHelp,
Expand All @@ -74,30 +75,35 @@ class _CIDRFieldState extends State<CIDRField> {
widget.onChanged!(cidr);
},
controller: widget.ipController,
))),
Text("/"),
Container(
width: Utils.textSize("bits", textStyle).width + 12,
padding: EdgeInsets.fromLTRB(2, 6, 6, 6),
child: SpecialTextField(
keyboardType: TextInputType.number,
focusNode: bitsFocus,
nextFocusNode: widget.nextFocusNode,
controller: widget.bitsController,
onChanged: (val) {
if (widget.onChanged == null) {
return;
}
),
),
),
Text("/"),
Container(
width: Utils.textSize("bits", textStyle).width + 12,
padding: EdgeInsets.fromLTRB(2, 6, 6, 6),
child: SpecialTextField(
keyboardType: TextInputType.number,
focusNode: bitsFocus,
nextFocusNode: widget.nextFocusNode,
controller: widget.bitsController,
onChanged: (val) {
if (widget.onChanged == null) {
return;
}

cidr.bits = int.tryParse(val) ?? 0;
widget.onChanged!(cidr);
},
maxLength: 2,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
textInputAction: widget.textInputAction ?? TextInputAction.done,
placeholder: 'bits',
))
]));
cidr.bits = int.tryParse(val) ?? 0;
widget.onChanged!(cidr);
},
maxLength: 2,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
textInputAction: widget.textInputAction ?? TextInputAction.done,
placeholder: 'bits',
),
),
],
),
);
}

@override
Expand Down
96 changes: 51 additions & 45 deletions lib/components/CIDRFormField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,57 @@ class CIDRFormField extends FormField<CIDR> {
this.ipController,
this.bitsController,
}) : super(
key: key,
initialValue: initialValue,
onSaved: onSaved,
validator: (cidr) {
if (cidr == null) {
return "Please fill out this field";
}

if (!ipValidator(cidr.ip, enableIPV6)) {
return 'Please enter a valid ip address';
}

if (cidr.bits > 32 || cidr.bits < 0) {
return "Please enter a valid number of bits";
}

return null;
},
builder: (FormFieldState<CIDR> field) {
final _CIDRFormField state = field as _CIDRFormField;

void onChangedHandler(CIDR value) {
if (onChanged != null) {
onChanged(value);
}
field.didChange(value);
}

return Column(crossAxisAlignment: CrossAxisAlignment.end, children: <Widget>[
CIDRField(
autoFocus: autoFocus,
focusNode: focusNode,
nextFocusNode: nextFocusNode,
onChanged: onChangedHandler,
textInputAction: textInputAction,
ipController: state._effectiveIPController,
bitsController: state._effectiveBitsController,
),
field.hasError
? Text(field.errorText ?? "Unknown error",
style: TextStyle(color: CupertinoColors.systemRed.resolveFrom(field.context), fontSize: 13),
textAlign: TextAlign.end)
: Container(height: 0)
]);
});
key: key,
initialValue: initialValue,
onSaved: onSaved,
validator: (cidr) {
if (cidr == null) {
return "Please fill out this field";
}

if (!ipValidator(cidr.ip, enableIPV6)) {
return 'Please enter a valid ip address';
}

if (cidr.bits > 32 || cidr.bits < 0) {
return "Please enter a valid number of bits";
}

return null;
},
builder: (FormFieldState<CIDR> field) {
final _CIDRFormField state = field as _CIDRFormField;

void onChangedHandler(CIDR value) {
if (onChanged != null) {
onChanged(value);
}
field.didChange(value);
}

return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
CIDRField(
autoFocus: autoFocus,
focusNode: focusNode,
nextFocusNode: nextFocusNode,
onChanged: onChangedHandler,
textInputAction: textInputAction,
ipController: state._effectiveIPController,
bitsController: state._effectiveBitsController,
),
field.hasError
? Text(
field.errorText ?? "Unknown error",
style: TextStyle(color: CupertinoColors.systemRed.resolveFrom(field.context), fontSize: 13),
textAlign: TextAlign.end,
)
: Container(height: 0),
],
);
},
);

final TextEditingController? ipController;
final TextEditingController? bitsController;
Expand Down
22 changes: 14 additions & 8 deletions lib/components/DangerButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ class DangerButton extends StatelessWidget {
Widget build(BuildContext context) {
if (Platform.isAndroid) {
return FilledButton(
onPressed: onPressed,
child: child,
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError));
onPressed: onPressed,
child: child,
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
),
);
} else {
// Workaround for https://github.com/flutter/flutter/issues/161590
final themeData = CupertinoTheme.of(context);
return CupertinoTheme(
data: themeData.copyWith(primaryColor: CupertinoColors.white),
child: CupertinoButton(
child: child, onPressed: onPressed, color: CupertinoColors.systemRed.resolveFrom(context)));
data: themeData.copyWith(primaryColor: CupertinoColors.white),
child: CupertinoButton(
child: child,
onPressed: onPressed,
color: CupertinoColors.systemRed.resolveFrom(context),
),
);
}
}
}
120 changes: 68 additions & 52 deletions lib/components/FormPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import 'package:mobile_nebula/services/utils.dart';

/// SimplePage with a form and built in validation and confirmation to discard changes if any are made
class FormPage extends StatefulWidget {
const FormPage(
{Key? key,
required this.title,
required this.child,
required this.onSave,
required this.changed,
this.hideSave = false,
this.scrollController})
: super(key: key);
const FormPage({
Key? key,
required this.title,
required this.child,
required this.onSave,
required this.changed,
this.hideSave = false,
this.scrollController,
}) : super(key: key);

final String title;
final Function onSave;
Expand All @@ -39,42 +39,61 @@ class _FormPageState extends State<FormPage> {
changed = widget.changed || changed;

return PopScope<Object?>(
canPop: !changed,
onPopInvokedWithResult: (bool didPop, Object? result) async {
if (didPop) {
return;
}
final NavigatorState navigator = Navigator.of(context);
canPop: !changed,
onPopInvokedWithResult: (bool didPop, Object? result) async {
if (didPop) {
return;
}
final NavigatorState navigator = Navigator.of(context);

Utils.confirmDelete(context, 'Discard changes?', () {
Utils.confirmDelete(
context,
'Discard changes?',
() {
navigator.pop();
}, deleteLabel: 'Yes', cancelLabel: 'No');
},
child: SimplePage(
leadingAction: _buildLeader(context),
trailingActions: _buildTrailer(context),
scrollController: widget.scrollController,
title: Text(widget.title),
child: Form(
key: _formKey,
onChanged: () => setState(() {
changed = true;
}),
child: widget.child),
));
},
deleteLabel: 'Yes',
cancelLabel: 'No',
);
},
child: SimplePage(
leadingAction: _buildLeader(context),
trailingActions: _buildTrailer(context),
scrollController: widget.scrollController,
title: Text(widget.title),
child: Form(
key: _formKey,
onChanged:
() => setState(() {
changed = true;
}),
child: widget.child,
),
),
);
}

Widget _buildLeader(BuildContext context) {
return Utils.leadingBackWidget(context, label: changed ? 'Cancel' : 'Back', onPressed: () {
if (changed) {
Utils.confirmDelete(context, 'Discard changes?', () {
changed = false;
return Utils.leadingBackWidget(
context,
label: changed ? 'Cancel' : 'Back',
onPressed: () {
if (changed) {
Utils.confirmDelete(
context,
'Discard changes?',
() {
changed = false;
Navigator.pop(context);
},
deleteLabel: 'Yes',
cancelLabel: 'No',
);
} else {
Navigator.pop(context);
}, deleteLabel: 'Yes', cancelLabel: 'No');
} else {
Navigator.pop(context);
}
});
}
},
);
}

List<Widget> _buildTrailer(BuildContext context) {
Expand All @@ -83,21 +102,18 @@ class _FormPageState extends State<FormPage> {
}

return [
Utils.trailingSaveWidget(
context,
() {
if (_formKey.currentState == null) {
return;
}
Utils.trailingSaveWidget(context, () {
if (_formKey.currentState == null) {
return;
}

if (!_formKey.currentState!.validate()) {
return;
}
if (!_formKey.currentState!.validate()) {
return;
}

_formKey.currentState!.save();
widget.onSave();
},
)
_formKey.currentState!.save();
widget.onSave();
}),
];
}
}
Loading

0 comments on commit 6c1042a

Please sign in to comment.