12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import 'package:flutter/material.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
- /// Time : 09/03/2023 Sunday
- /// Author : liuyuqi.gov@msn.cn
- class HomePage extends StatefulWidget {
- const HomePage({super.key});
- static bool hasData = false;
- @override
- State<HomePage> createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage>
- with SingleTickerProviderStateMixin {
- late TabController tabController;
- @override
- void initState() {
- super.initState();
- tabController = TabController(length: 3, vsync: this);
- }
- @override
- Widget build(BuildContext context) {
- 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),
- ),
- ),
- );
- }
- }
|