238 lines
7.5 KiB
Dart
238 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:bruno/bruno.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:yaml/yaml.dart';
|
||
import '../../../app/enum/config_path_enum.dart';
|
||
import '../../../core/di/providers.dart';
|
||
import '../../../core/utils/extensions/dialogUtils.dart';
|
||
import '../../stock/presentation/screens/stock_in_empty_screen.dart';
|
||
import '../../stock/presentation/screens/stock_in_manual_screen.dart';
|
||
import '../../stock/presentation/screens/stock_out_empty_screen.dart';
|
||
|
||
class Home extends ConsumerStatefulWidget {
|
||
const Home({super.key});
|
||
|
||
@override
|
||
ConsumerState<Home> createState() => _HomePageState();
|
||
}
|
||
|
||
class _HomePageState extends ConsumerState<Home> {
|
||
List<BrnDoughnutDataItem> stockChartsData = [];
|
||
late Color primaryColor;
|
||
bool _isLoading = true;
|
||
AsyncValue<void>? _previousState;
|
||
bool _hasSubmitted = false;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_loadConfig();
|
||
setState(() {
|
||
stockChartsData = [
|
||
BrnDoughnutDataItem(value: 40, title: "空闲", color: Colors.green),
|
||
BrnDoughnutDataItem(value: 60, title: "占用", color: Colors.orange),
|
||
];
|
||
});
|
||
}
|
||
|
||
@override
|
||
void didChangeDependencies() {
|
||
super.didChangeDependencies();
|
||
|
||
final currentState = ref.read(pageNotifierProvider);
|
||
|
||
if (_previousState != currentState && _hasSubmitted) {
|
||
_previousState = currentState;
|
||
Future.microtask(() => _handleState(currentState));
|
||
} else {
|
||
_previousState = currentState;
|
||
}
|
||
}
|
||
|
||
Future<void> _loadConfig() async {
|
||
final configString = await rootBundle.loadString(
|
||
ConfigPathEnum.uiConfig.configPath,
|
||
);
|
||
final config = loadYaml(configString);
|
||
setState(() {
|
||
primaryColor = Color(config['theme']['primaryColor']);
|
||
_isLoading = false;
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
if (_isLoading) {
|
||
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
||
}
|
||
|
||
ref.listen(pageNotifierProvider, (previous, next) {
|
||
if (previous != next && _hasSubmitted) {
|
||
_previousState = next;
|
||
Future.microtask(() => _handleState(next));
|
||
}
|
||
});
|
||
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
iconTheme: const IconThemeData(color: Colors.white),
|
||
centerTitle: true,
|
||
backgroundColor: primaryColor,
|
||
title: const Text("WMS移动终端(模板)", style: TextStyle(color: Colors.white)),
|
||
),
|
||
drawer: Drawer(
|
||
backgroundColor: Colors.white,
|
||
child: ListView(
|
||
padding: const EdgeInsets.all(0),
|
||
children: [
|
||
UserAccountsDrawerHeader(
|
||
accountName: const Text("模板"),
|
||
accountEmail: const Text("欢迎使用WMS移动终端"),
|
||
decoration: BoxDecoration(color: primaryColor),
|
||
),
|
||
ListTile(
|
||
title: const Text("空载具入库"),
|
||
trailing: const Icon(Icons.grain),
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(builder: (context) => const StockInEmpty()),
|
||
);
|
||
},
|
||
),
|
||
ListTile(
|
||
title: const Text("手动码盘入库"),
|
||
trailing: const Icon(Icons.add_box),
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => const StockInManual(),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
// ListTile(
|
||
// title: const Text("EBS码盘入库"),
|
||
// trailing: const Icon(Icons.add_box),
|
||
// onTap: () {
|
||
// Navigator.push(
|
||
// context,
|
||
// MaterialPageRoute(
|
||
// builder: (context) => const StockInEBS(),
|
||
// ),
|
||
// );
|
||
// },
|
||
// ),
|
||
ListTile(
|
||
title: const Text("呼叫空托"),
|
||
trailing: const Icon(Icons.ac_unit),
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => const StockOutEmpty(),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
// ListTile(
|
||
// title: const Text("出库拣货"),
|
||
// trailing: const Icon(Icons.back_hand),
|
||
// onTap: () {
|
||
// Navigator.push(
|
||
// context,
|
||
// MaterialPageRoute(builder: (context) => const Pick()),
|
||
// );
|
||
// },
|
||
// ),
|
||
|
||
// ListTile(title: const Text("库存盘点"), trailing: const Icon(Icons.checklist), onTap: () {
|
||
// Navigator.push(context, MaterialPageRoute(builder: (context) => const StockCheck()));
|
||
// }),
|
||
// ListTile(title: const Text("库存查询"), trailing: const Icon(Icons.list_alt), onTap: () {
|
||
// Navigator.push(context, MaterialPageRoute(builder: (context) => const StockSearch()));
|
||
// })
|
||
],
|
||
),
|
||
),
|
||
body: Padding(
|
||
padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
|
||
child: ListView(
|
||
children: [
|
||
const Text("库存占用情况:"),
|
||
Row(
|
||
children: [
|
||
Column(
|
||
children: [
|
||
BrnDoughnutChart(
|
||
padding: const EdgeInsets.all(50),
|
||
width: 150,
|
||
height: 150,
|
||
data: stockChartsData,
|
||
showTitleWhenSelected: false,
|
||
),
|
||
],
|
||
),
|
||
Column(
|
||
children: [
|
||
DoughnutChartLegend(
|
||
data: stockChartsData,
|
||
legendStyle: BrnDoughnutChartLegendStyle.list,
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
Padding(
|
||
padding: const EdgeInsets.only(top: 10),
|
||
child: SizedBox(
|
||
width: 250,
|
||
child: ElevatedButton(
|
||
onPressed: test,
|
||
style: ButtonStyle(
|
||
backgroundColor: MaterialStateProperty.all(primaryColor),
|
||
),
|
||
child: const Text(
|
||
"网络检测",
|
||
style: TextStyle(color: Colors.white),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void test() {
|
||
// 标记已提交请求
|
||
_hasSubmitted = true;
|
||
ref.read(pageNotifierProvider.notifier).submit();
|
||
}
|
||
|
||
void _handleState(AsyncValue<void> state) {
|
||
state.whenOrNull(
|
||
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
||
error: (error, _) {
|
||
BrnLoadingDialog.dismiss(context);
|
||
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
||
},
|
||
data: (_) {
|
||
BrnLoadingDialog.dismiss(context);
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: Text("请求成功"),
|
||
duration: const Duration(seconds: 2),
|
||
behavior: SnackBarBehavior.floating,
|
||
backgroundColor: Colors.green,
|
||
margin: const EdgeInsets.only(bottom: 100, left: 20, right: 20),
|
||
),
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|