104 lines
No EOL
3.4 KiB
Dart
104 lines
No EOL
3.4 KiB
Dart
// Version: 3.0 - リッチマスター編集ダイアログ(簡素版、全てのマスタで共通使用)
|
|
import 'package:flutter/material.dart';
|
|
import '../models/product.dart';
|
|
import '../services/database_helper.dart';
|
|
|
|
/// 汎用性の高いリッチなマスター編集ダイアログ(簡素版)
|
|
class MasterEditDialog<T extends Product> extends StatefulWidget {
|
|
final String title;
|
|
final T? initialData;
|
|
final bool showStatusFields;
|
|
final Function(T)? onSave;
|
|
|
|
const MasterEditDialog({
|
|
super.key,
|
|
required this.title,
|
|
this.initialData,
|
|
this.showStatusFields = false,
|
|
this.onSave,
|
|
});
|
|
|
|
@override
|
|
State<MasterEditDialog> createState() => _MasterEditDialogState();
|
|
}
|
|
|
|
class _MasterEditDialogState extends State<MasterEditDialog> {
|
|
late TextEditingController codeController;
|
|
late TextEditingController nameController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final data = widget.initialData;
|
|
codeController = TextEditingController(text: data?.productCode ?? '');
|
|
nameController = TextEditingController(text: data?.name ?? '');
|
|
}
|
|
|
|
bool showStatusField() => widget.showStatusFields;
|
|
|
|
Widget _buildEditField(String label, TextEditingController controller) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 8),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
TextField(controller: controller, decoration: InputDecoration(hintText: '入力をここに', border: OutlineInputBorder())),
|
|
],),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(widget.title),
|
|
content: SingleChildScrollView(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
style: ElevatedButton.styleFrom(padding: const EdgeInsets.only(top: 8)),
|
|
child: const Text('キャンセル'),
|
|
),
|
|
|
|
_buildEditField('製品コード *', codeController),
|
|
|
|
_buildEditField('会社名 *', nameController),
|
|
|
|
if (widget.showStatusFields) ...[
|
|
const SizedBox(height: 16),
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(border: Border.all(color: Colors.grey.shade300)),
|
|
child: const Text('ステータス管理(簡素版)」', textAlign: TextAlign.center),
|
|
),
|
|
],
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.pop(context, widget.onSave?.call(widget.initialData! as T)),
|
|
child: const Text('保存'),
|
|
),
|
|
],),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 参照マスタ選択ダイアログ(簡素版)
|
|
class SingleChoiceDialog extends StatelessWidget {
|
|
final List<Product> items;
|
|
final Function() onCancel;
|
|
final Function(Product) onSelected;
|
|
|
|
const SingleChoiceDialog({super.key, required this.items, required this.onCancel, required this.onSelected});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (items.isEmpty) return const Text('検索結果がありません');
|
|
|
|
return ListView.builder(
|
|
shrinkWrap: true,
|
|
itemCount: items.length,
|
|
itemBuilder: (ctx, index) => ListTile(title: Text(items[index].name ?? '未入力'), onTap: () => onSelected(items[index])),
|
|
);
|
|
}
|
|
} |