201 lines
No EOL
5.4 KiB
Dart
201 lines
No EOL
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// マスタ編集用の汎用テキストフィールドウィジェット
|
|
class MasterTextField extends StatelessWidget {
|
|
final String label;
|
|
final String? initialValue;
|
|
final String? hintText;
|
|
final VoidCallback? onTap;
|
|
|
|
const MasterTextField({
|
|
super.key,
|
|
required this.label,
|
|
this.initialValue,
|
|
this.hintText,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
TextFormField(
|
|
initialValue: initialValue,
|
|
decoration: InputDecoration(
|
|
hintText: hintText,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
|
|
),
|
|
onTap: onTap,
|
|
textInputAction: TextInputAction.done,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// マスタ編集用の汎用数値フィールドウィジェット
|
|
class MasterNumberField extends StatelessWidget {
|
|
final String label;
|
|
final double? initialValue;
|
|
final String? hintText;
|
|
final VoidCallback? onTap;
|
|
|
|
const MasterNumberField({
|
|
super.key,
|
|
required this.label,
|
|
this.initialValue,
|
|
this.hintText,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
TextFormField(
|
|
initialValue: initialValue?.toString(),
|
|
decoration: InputDecoration(
|
|
hintText: hintText,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
|
|
),
|
|
onTap: onTap,
|
|
keyboardType: TextInputType.number,
|
|
textInputAction: TextInputAction.done,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// ドロップダウンフィールドウィジェット
|
|
class MasterDropdownField<T> extends StatelessWidget {
|
|
final String label;
|
|
final List<String> options;
|
|
final String? selectedOption;
|
|
final VoidCallback? onTap;
|
|
|
|
const MasterDropdownField({
|
|
super.key,
|
|
required this.label,
|
|
required this.options,
|
|
this.selectedOption,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
DropdownButtonFormField<String>(
|
|
value: selectedOption,
|
|
items: options.map((option) => DropdownMenuItem<String>(
|
|
value: option,
|
|
child: Text(option),
|
|
)).toList(),
|
|
decoration: InputDecoration(
|
|
hintText: options.isEmpty ? null : options.first,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
|
|
),
|
|
onTap: onTap,
|
|
isExpanded: true,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// テキストエリアウィジェット
|
|
class MasterTextArea extends StatelessWidget {
|
|
final String label;
|
|
final String? initialValue;
|
|
final String? hintText;
|
|
final VoidCallback? onTap;
|
|
|
|
const MasterTextArea({
|
|
super.key,
|
|
required this.label,
|
|
this.initialValue,
|
|
this.hintText,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
TextFormField(
|
|
initialValue: initialValue,
|
|
decoration: InputDecoration(
|
|
hintText: hintText,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
|
|
),
|
|
maxLines: 3,
|
|
onTap: onTap,
|
|
textInputAction: TextInputAction.newline,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// チェックボックスウィジェット
|
|
class MasterCheckBox extends StatelessWidget {
|
|
final String label;
|
|
final bool? initialValue;
|
|
final VoidCallback? onChanged;
|
|
|
|
const MasterCheckBox({
|
|
super.key,
|
|
required this.label,
|
|
this.initialValue,
|
|
this.onChanged,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(label)),
|
|
Checkbox(
|
|
value: initialValue,
|
|
onChanged: onChanged ?? (_ => null),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |