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

60 lines
No EOL
2.1 KiB
Dart

// Version: 4.0 - 顧客マスタ画面(超簡素版、サンプルデータ固定)
// ※ データベース連携なし:動作保証版
import 'package:flutter/material.dart';
class CustomerMasterScreen extends StatefulWidget {
const CustomerMasterScreen({super.key});
@override
State<CustomerMasterScreen> createState() => _CustomerMasterScreenState();
}
class _CustomerMasterScreenState extends State<CustomerMasterScreen> {
List<Map<String, dynamic>> _customers = [];
@override
void initState() {
super.initState();
// サンプルデータを初期化(簡素版)
_customers = [
{'customer_code': 'C001', 'name': 'サンプル顧客 A'},
{'customer_code': 'C002', 'name': 'サンプル顧客 B'},
];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('/M2. 顧客マスタ')),
body: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: _customers.length,
itemBuilder: (context, index) {
final customer = _customers[index];
return Card(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.green.shade100,
child: Text(customer['customer_code'] ?? '-', style: const TextStyle(fontWeight: FontWeight.bold)),
),
title: Text(customer['name'] ?? '未入力'),
),
);
},
),
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.add),
label: const Text('新規登録'),
onPressed: () {
// 簡素化:サンプルデータを追加してダイアログを閉じる
setState(() {
_customers = [..._customers, {'customer_code': 'C${_customers.isEmpty ? '003' : '${_customers.length.toString().padLeft(2, '0')}'}', 'name': ''}];
});
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('登録完了')));
},
),
);
}
}