123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:hengyi/data/country_entity.dart';
- import 'package:hengyi/home/item_country.dart';
- import 'package:hengyi/utils/dio_util.dart';
- class CountryDataWidget extends StatefulWidget {
- CountryDataWidget(this.id, {super.key});
- final int id;
- @override
- State<CountryDataWidget> createState() => _CountryDataWidgetState();
- }
- class _CountryDataWidgetState extends State<CountryDataWidget> {
- List<CountryEntity> list = [];
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: EdgeInsets.only(left: 200.w, right: 200.w),
- child: FutureBuilder(
- future: NetworkUtil().getCountryList(widget.id),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- if (snapshot.hasData) {
- list.addAll(snapshot.data!);
- return GridView(
- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 4,
- childAspectRatio: 1,
- ),
- children: List.generate(list.length, (index) {
- return CountryItemWidget(list[index]);
- }),
- );
- } else {
- return Text("Error:${snapshot.error}");
- }
- } else {
- return Container(
- alignment: Alignment.center,
- child: const CircularProgressIndicator(),
- );
- }
- }),
- );
- }
- }
|