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 createState() => _HomePageState(); } class _HomePageState extends State with SingleTickerProviderStateMixin { late TabController tabController; @override void initState() { super.initState(); tabController = TabController(length: 3, vsync: this); } @override Widget build(BuildContext context) { Provider.of(context).getCars(); if (Provider.of(context).count > 0) { HomePage.hasData = true; } return Scaffold( appBar: AppBar( title: const Text('Your Cars'), actions: [ IconButton( icon: const Icon(Icons.add), onPressed: () { Navigator.of(context).push( MaterialPageRoute(builder: (context) => const AddcardPage())); }, ), ], bottom: TabBar( controller: tabController, tabs: const [ Tab(text: 'UnReady'), Tab(text: 'All'), Tab(text: 'Ready'), ], ), ), body: Provider.of(context).count > 0 ? TabBarView( controller: tabController, children: const [ AllCarsTab(), UnReadyCarsTab(), ReadyCarsTab() ], ) : const Center( child: Text( '', style: TextStyle(fontSize: 20.0), ), ), ); } }