h-1.flutter.4/lib/screens/master/product_master_screen.dart

148 lines
No EOL
4.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Version: 1.0.0
import 'package:flutter/material.dart';
/// 商品マスタ画面Material Design 標準テンプレート)
class ProductMasterScreen extends StatelessWidget {
const ProductMasterScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('商品マスタ'),
actions: [
IconButton(
icon: const Icon(Icons.add),
onPressed: () => _showAddDialog(context),
),
],
),
body: ListView(
padding: const EdgeInsets.all(8),
children: [
// ヘッダー
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'商品コード',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
// テーブル形式のリスト(標準 Material 部品)
ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.zero,
itemCount: 5, // デモ用データ数
itemBuilder: (context, index) {
return Card(
margin: const EdgeInsets.symmetric(vertical: 4),
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.blue.shade100,
child: Icon(Icons.shopping_basket, color: Colors.blue),
),
title: Text('商品${index + 1}'),
subtitle: Text('JAN: ${'123456789'.padLeft(10, '0')}'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.edit),
onPressed: () => _showEditDialog(context, index),
),
IconButton(
icon: const Icon(Icons.delete),
onPressed: () => _showDeleteDialog(context, index),
),
],
),
),
);
},
),
],
),
);
}
void _showAddDialog(BuildContext context) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('新規商品登録'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
decoration: const InputDecoration(
labelText: '商品コード',
hintText: 'JAN 形式で入力',
),
),
const SizedBox(height: 8),
TextField(
decoration: const InputDecoration(
labelText: '品名',
),
),
const SizedBox(height: 8),
TextField(
decoration: const InputDecoration(
labelText: '単価',
hintText: '¥ の後に数字のみ入力',
),
keyboardType: TextInputType.number,
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('キャンセル'),
),
ElevatedButton(
onPressed: () {
Navigator.pop(ctx);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('商品登録しました')),
);
},
child: const Text('保存'),
),
],
),
);
}
void _showEditDialog(BuildContext context, int index) {
// 編集ダイアログ(構造は新規と同様)
}
void _showDeleteDialog(BuildContext context, int index) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('商品削除'),
content: Text('商品${index + 1}を削除しますか?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('キャンセル'),
),
ElevatedButton(
onPressed: () {
Navigator.pop(ctx);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('商品削除しました')),
);
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
child: const Text('削除'),
),
],
),
);
}
}