country_list.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:flutter/material.dart';
  2. import 'package:hengyi/data/continent_entity.dart';
  3. import 'package:hengyi/home/asia_view.dart';
  4. import 'package:hengyi/utils/dio_util.dart';
  5. class CountryListWidget extends StatefulWidget {
  6. const CountryListWidget({super.key});
  7. @override
  8. State<CountryListWidget> createState() => _CountryListWidgetState();
  9. }
  10. class _CountryListWidgetState extends State<CountryListWidget>
  11. with SingleTickerProviderStateMixin {
  12. TabController? _tabController;
  13. List<ContinentEntity> tabs = [];
  14. @override
  15. void initState() {
  16. super.initState();
  17. }
  18. @override
  19. Widget build(BuildContext context) {
  20. return Scaffold(
  21. body: FutureBuilder(
  22. future: NetworkUtil().getContinentList(),
  23. builder: (context, snapshot) {
  24. if (snapshot.connectionState == ConnectionState.done) {
  25. if (snapshot.hasData) {
  26. tabs.addAll(snapshot.data!);
  27. _tabController ??=
  28. TabController(length: tabs.length, vsync: this);
  29. return Column(
  30. children: [
  31. TabBar(
  32. isScrollable: true,
  33. labelColor: Colors.black,
  34. unselectedLabelColor: Colors.grey,
  35. controller: _tabController,
  36. tabs: tabs
  37. .map((e) => Tab(
  38. text: e.partName,
  39. ))
  40. .toList()),
  41. Expanded(
  42. child: TabBarView(
  43. controller: _tabController,
  44. children: tabs
  45. .map((e) => CountryDataWidget(e.id))
  46. .toList()))
  47. ],
  48. );
  49. } else {
  50. return Text("Error:${snapshot.error}");
  51. }
  52. } else {
  53. return Container(
  54. alignment: Alignment.center,
  55. child: const CircularProgressIndicator(),
  56. );
  57. }
  58. }),
  59. );
  60. }
  61. }