mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 17:26:18 +01:00
39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/widgets.dart';
|
||
|
|
||
|
class SwitchFormField extends FormField<bool> {
|
||
|
SwitchFormField({
|
||
|
Key? key,
|
||
|
required bool initialValue,
|
||
|
Widget? title,
|
||
|
Widget? subtitle,
|
||
|
Widget? subtitleTrue,
|
||
|
Widget? subtitleFalse,
|
||
|
bool? dense,
|
||
|
FormFieldSetter<bool>? onSaved,
|
||
|
FormFieldValidator<bool>? validator,
|
||
|
bool enabled = true,
|
||
|
AutovalidateMode? autovalidateMode,
|
||
|
}) : super(
|
||
|
key: key,
|
||
|
onSaved: onSaved,
|
||
|
validator: validator,
|
||
|
initialValue: initialValue,
|
||
|
enabled: enabled,
|
||
|
autovalidateMode: autovalidateMode,
|
||
|
builder: (field) {
|
||
|
final value = field.value ?? initialValue;
|
||
|
return SwitchListTile(
|
||
|
value: value,
|
||
|
contentPadding: const EdgeInsets.all(0),
|
||
|
title: title,
|
||
|
subtitle: value
|
||
|
? (subtitleTrue ?? subtitle)
|
||
|
: (subtitleFalse ?? subtitle),
|
||
|
dense: dense,
|
||
|
onChanged: field.didChange,
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|