|
@@ -1,27 +1,76 @@
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
-import 'package:flutter_provider_demo/routes.dart';
|
|
|
|
|
|
+import 'package:flutter_provider_demo/pages/addpage_page.dart';
|
|
|
|
+import 'package:flutter_provider_demo/provider/car_provider.dart';
|
|
|
|
+import 'package:flutter_provider_demo/views/all_cars.dart';
|
|
|
|
+import 'package:flutter_provider_demo/views/ready_cars.dart';
|
|
|
|
+import 'package:flutter_provider_demo/views/unready_cars.dart';
|
|
|
|
+import 'package:provider/provider.dart';
|
|
|
|
|
|
/// Description: home page
|
|
/// Description: home page
|
|
/// Time : 09/03/2023 Sunday
|
|
/// Time : 09/03/2023 Sunday
|
|
/// Author : liuyuqi.gov@msn.cn
|
|
/// Author : liuyuqi.gov@msn.cn
|
|
-class MyWidget extends StatefulWidget {
|
|
|
|
- const MyWidget({super.key});
|
|
|
|
|
|
+class HomePage extends StatefulWidget {
|
|
|
|
+ const HomePage({super.key});
|
|
|
|
+ static bool hasData = false;
|
|
|
|
|
|
@override
|
|
@override
|
|
- State<MyWidget> createState() => _MyWidgetState();
|
|
|
|
|
|
+ State<HomePage> createState() => _HomePageState();
|
|
}
|
|
}
|
|
|
|
|
|
-class _MyWidgetState extends State<MyWidget> {
|
|
|
|
|
|
+class _HomePageState extends State<HomePage>
|
|
|
|
+ with SingleTickerProviderStateMixin {
|
|
|
|
+ late TabController tabController;
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void initState() {
|
|
|
|
+ super.initState();
|
|
|
|
+ tabController = TabController(length: 3, vsync: this);
|
|
|
|
+ }
|
|
|
|
+
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
- return const Scaffold(
|
|
|
|
- appBar: AppBar(actions: [
|
|
|
|
- IconButton(icon: Icon(Icons.add), onPressed: () {
|
|
|
|
- Navigator.pushNamed(context, Routes.carAdd);
|
|
|
|
- }),
|
|
|
|
- }),
|
|
|
|
- ], title: Text('汽车列表'),),
|
|
|
|
- ], title: Text('汽车列表'),'))]),
|
|
|
|
|
|
+ Provider.of<CarProvider>(context).getCars();
|
|
|
|
+
|
|
|
|
+ if (Provider.of<CarProvider>(context).count > 0) {
|
|
|
|
+ HomePage.hasData = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Scaffold(
|
|
|
|
+ appBar: AppBar(
|
|
|
|
+ title: const Text('Your Cars'),
|
|
|
|
+ actions: <Widget>[
|
|
|
|
+ IconButton(
|
|
|
|
+ icon: const Icon(Icons.add),
|
|
|
|
+ onPressed: () {
|
|
|
|
+ Navigator.of(context).push(
|
|
|
|
+ MaterialPageRoute(builder: (context) => const AddcardPage()));
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ bottom: TabBar(
|
|
|
|
+ controller: tabController,
|
|
|
|
+ tabs: const <Widget>[
|
|
|
|
+ Tab(text: 'UnReady'),
|
|
|
|
+ Tab(text: 'All'),
|
|
|
|
+ Tab(text: 'Ready'),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ body: Provider.of<CarProvider>(context).count > 0
|
|
|
|
+ ? TabBarView(
|
|
|
|
+ controller: tabController,
|
|
|
|
+ children: const <Widget>[
|
|
|
|
+ AllCarsTab(),
|
|
|
|
+ UnReadyCarsTab(),
|
|
|
|
+ ReadyCarsTab()
|
|
|
|
+ ],
|
|
|
|
+ )
|
|
|
|
+ : const Center(
|
|
|
|
+ child: Text(
|
|
|
|
+ '',
|
|
|
|
+ style: TextStyle(fontSize: 20.0),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|