feat: add Flutter mobile clients and staff delivery API

This commit is contained in:
david
2026-07-30 21:47:41 +08:00
parent 550efb3812
commit 36a5ced1c0
228 changed files with 17159 additions and 22 deletions

View File

@@ -0,0 +1,175 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:uuid/uuid.dart';
import '../../../app/dependencies.dart';
import '../../../data/repositories/client_repository.dart';
import '../../../domain/models/client_models.dart';
class ProfilePage extends StatefulWidget {
const ProfilePage({required this.session, required this.repository, super.key});
final UserSession session;
final ClientRepository repository;
@override
State<ProfilePage> createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
late Future<(UserProfile, WalletSummary)> _future;
@override
void initState() {
super.initState();
_future = _load();
}
Future<(UserProfile, WalletSummary)> _load() async =>
(await widget.repository.profile(), await widget.repository.wallet());
Future<void> _addAddress() async {
final controller = TextEditingController();
final address = await showDialog<String>(
context: context,
builder: (context) => AlertDialog(
title: const Text('新增地址'),
content: TextField(
controller: controller,
decoration: const InputDecoration(labelText: '详细地址'),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
FilledButton(
onPressed: () => Navigator.pop(context, controller.text.trim()),
child: const Text('保存'),
),
],
),
);
controller.dispose();
if (address == null || address.isEmpty) return;
await widget.repository.addAddress(address, isDefault: true);
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('地址已保存')));
}
Future<void> _createTicket() async {
final controller = TextEditingController();
final description = await showDialog<String>(
context: context,
builder: (context) => AlertDialog(
title: const Text('申请维修'),
content: TextField(
controller: controller,
maxLines: 4,
decoration: const InputDecoration(labelText: '问题描述'),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
FilledButton(
onPressed: () => Navigator.pop(context, controller.text.trim()),
child: const Text('提交'),
),
],
),
);
controller.dispose();
if (description == null || description.isEmpty) return;
await widget.repository.createTicket(
requestNo: const Uuid().v7(),
category: 'repair',
description: description,
);
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('工单已提交')));
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('我的')),
body: FutureBuilder<(UserProfile, WalletSummary)>(
future: _future,
builder: (context, snapshot) {
if (!snapshot.hasData) {
if (snapshot.hasError) return Center(child: Text(snapshot.error.toString()));
return const Center(child: CircularProgressIndicator());
}
final (profile, wallet) = snapshot.data!;
return ListView(
padding: const EdgeInsets.all(16),
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Row(
children: [
CircleAvatar(
radius: 30,
child: Text(profile.name.isEmpty ? '' : profile.name.substring(0, 1)),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
profile.name,
style: Theme.of(
context,
).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w800),
),
Text(profile.phone),
],
),
),
],
),
),
),
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('钱包余额'),
SizedBox(height: 4),
Text('充值结果以服务端确认为准', style: TextStyle(fontSize: 12)),
],
),
Text(
moneyText(wallet.balance),
style: Theme.of(
context,
).textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.w900),
),
],
),
),
),
_item(Icons.location_on_outlined, '地址管理', _addAddress),
_item(Icons.description_outlined, '供气合同', () => context.push('/records/contracts')),
_item(
Icons.account_balance_wallet_outlined,
'钱包流水',
() => context.push('/records/wallet'),
),
_item(Icons.build_outlined, '申请维修', _createTicket),
_item(Icons.logout, '退出登录', widget.session.logout),
],
);
},
),
);
Widget _item(IconData icon, String title, VoidCallback onTap) => Card(
child: ListTile(
leading: Icon(icon),
title: Text(title),
trailing: const Icon(Icons.chevron_right),
onTap: onTap,
),
);
}