125 lines
No EOL
3.2 KiB
Dart
125 lines
No EOL
3.2 KiB
Dart
// Version: 1.0 - 汎用マスタ編集フィールド(Flutter 標準)
|
||
import 'package:flutter/material.dart';
|
||
|
||
/// マスタ編集用の統一 TextField
|
||
class MasterTextField extends StatelessWidget {
|
||
final String label;
|
||
final TextEditingController controller;
|
||
final String? hint;
|
||
final TextInputType keyboardType;
|
||
final bool obscureText;
|
||
final int maxLines;
|
||
final TextInputAction textInputAction;
|
||
final FormFieldValidator<String>? validator;
|
||
final void Function(String)? onChanged;
|
||
|
||
const MasterTextField({
|
||
super.key,
|
||
required this.label,
|
||
required this.controller,
|
||
this.hint,
|
||
this.keyboardType = TextInputType.text,
|
||
this.obscureText = false,
|
||
this.maxLines = 1,
|
||
this.textInputAction = TextInputAction.next,
|
||
this.validator,
|
||
this.onChanged,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return TextFormField(
|
||
controller: controller,
|
||
decoration: InputDecoration(
|
||
labelText: label,
|
||
hintText: hint,
|
||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||
),
|
||
keyboardType: keyboardType,
|
||
obscureText: obscureText,
|
||
maxLines: maxLines,
|
||
textInputAction: textInputAction,
|
||
validator: (value) => onChanged == null ? validator?.call(value) : 'Custom validation',
|
||
onChanged: onChanged,
|
||
);
|
||
}
|
||
}
|
||
|
||
/// マスタ編集用の数値入力 TextField
|
||
class MasterNumberField extends StatelessWidget {
|
||
final String label;
|
||
final TextEditingController controller;
|
||
final String? hint;
|
||
final FormFieldValidator<String>? validator;
|
||
final void Function(String)? onChanged;
|
||
|
||
const MasterNumberField({
|
||
super.key,
|
||
required this.label,
|
||
required this.controller,
|
||
this.hint,
|
||
this.validator,
|
||
this.onChanged,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return TextFormField(
|
||
controller: controller,
|
||
decoration: InputDecoration(
|
||
labelText: label,
|
||
hintText: hint,
|
||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||
),
|
||
keyboardType: TextInputType.number,
|
||
validator: (value) => onChanged == null ? validator?.call(value) : 'Custom validation',
|
||
onChanged: onChanged,
|
||
);
|
||
}
|
||
}
|
||
|
||
/// マスタ編集用の Checkbox
|
||
class MasterCheckboxField extends StatelessWidget {
|
||
final String label;
|
||
final bool value;
|
||
final ValueChanged<bool?>? onChangedCallback;
|
||
|
||
const MasterCheckboxField({
|
||
super.key,
|
||
required this.label,
|
||
required this.value,
|
||
this.onChangedCallback,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Checkbox(
|
||
value: value,
|
||
onChanged: onChangedCallback,
|
||
);
|
||
}
|
||
}
|
||
|
||
/// マスタ編集用の Switch
|
||
class MasterSwitchField extends StatelessWidget {
|
||
final String label;
|
||
final bool value;
|
||
final ValueChanged<bool>? onChangedCallback;
|
||
|
||
const MasterSwitchField({
|
||
super.key,
|
||
required this.label,
|
||
required this.value,
|
||
this.onChangedCallback,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Switch(
|
||
value: value,
|
||
onChanged: onChangedCallback,
|
||
);
|
||
}
|
||
} |