// Version: 4.0 - 簡素製品マスタ画面(サンプルデータ固定) // ※ データベース連携なし:動作保証版 import 'package:flutter/material.dart'; class ProductMasterScreen extends StatefulWidget { const ProductMasterScreen({super.key}); @override State createState() => _ProductMasterScreenState(); } class _ProductMasterScreenState extends State { List> _products = []; @override void initState() { super.initState(); // サンプルデータを初期化 _products = [ {'product_code': 'TEST001', 'name': 'サンプル商品 A', 'unit_price': 1000.0, 'quantity': 50}, {'product_code': 'TEST002', 'name': 'サンプル商品 B', 'unit_price': 2500.0, 'quantity': 30}, {'product_code': 'TEST003', 'name': 'サンプル商品 C', 'unit_price': 5000.0, 'quantity': 20}, ]; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('/M0. 製品マスタ')), body: ListView.builder( padding: const EdgeInsets.all(8), itemCount: _products.length, itemBuilder: (context, index) { final product = _products[index]; return Card( margin: EdgeInsets.zero, clipBehavior: Clip.antiAlias, child: ListTile( leading: CircleAvatar( backgroundColor: Colors.blue.shade100, child: Text(product['product_code'] ?? '-', style: const TextStyle(fontWeight: FontWeight.bold)), ), title: Text(product['name'] ?? '未入力'), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (product['unit_price'] != null) Text('単価:${product['unit_price']}円', style: const TextStyle(fontSize: 12)), if (product['quantity'] != null) Text('数量:${product['quantity']}', style: const TextStyle(fontSize: 12)), ], ), ), ); }, ), floatingActionButton: FloatingActionButton.extended( icon: const Icon(Icons.add), label: const Text('新規登録'), onPressed: () { setState(() { _products = [..._products, {'product_code': 'TEST00${_products.length + 1}', 'name': '新商品', 'unit_price': 0.0, 'quantity': 0}]; }); ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('登録完了'))); }, ), ); } }