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 createState() => _CountryListWidgetState(); } class _CountryListWidgetState extends State with SingleTickerProviderStateMixin { TabController? _tabController; List 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(), ); } }), ); } }