1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import 'package:flutter/material.dart';
- import 'package:hengyi/data/continent_entity.dart';
- import 'package:hengyi/home/asia_view.dart';
- import 'package:hengyi/utils/dio_util.dart';
- class CountryListWidget extends StatefulWidget {
- const CountryListWidget({super.key});
- @override
- State<CountryListWidget> createState() => _CountryListWidgetState();
- }
- class _CountryListWidgetState extends State<CountryListWidget>
- with SingleTickerProviderStateMixin {
- TabController? _tabController;
- List<ContinentEntity> tabs = [];
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: FutureBuilder(
- future: NetworkUtil().getContinentList(),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- if (snapshot.hasData) {
- tabs.addAll(snapshot.data!);
- _tabController ??=
- TabController(length: tabs.length, vsync: this);
- return Column(
- children: [
- TabBar(
- isScrollable: true,
- labelColor: Colors.black,
- unselectedLabelColor: Colors.grey,
- controller: _tabController,
- tabs: tabs
- .map((e) => Tab(
- text: e.partName,
- ))
- .toList()),
- Expanded(
- child: TabBarView(
- controller: _tabController,
- children: tabs
- .map((e) => CountryDataWidget(e.id))
- .toList()))
- ],
- );
- } else {
- return Text("Error:${snapshot.error}");
- }
- } else {
- return Container(
- alignment: Alignment.center,
- child: const CircularProgressIndicator(),
- );
- }
- }),
- );
- }
- }
|