Flutter
import 'package:country_house/pages/Country.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
class AllCountries extends StatefulWidget {
const AllCountries({Key? key}) : super(key: key);
@override
State<AllCountries> createState() => _AllCountriesState();
}
class _AllCountriesState extends State<AllCountries> {
Future<List> countries=[];
Future<List> getCountries() async {
var response = await Dio().get('https://restcountries.com/v3.1/all');
return response.data.length;
}
@override
void initState() {
countries = getCountries();
super.initState();
}
@override
Widget build(BuildContext context) {
getCountries();
return Scaffold(
appBar: AppBar(
title: Text('All Countries'),
centerTitle: true,
),
body: Container(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: FutureBuilder<List>(
future: countries,
builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
if (snapshot.hasData) {
return Text('hello');
}
return null;
}),
),
),
);
}
}
I get the following error: A value of type 'List' can't be assigned to a variable of type 'Future<List>'.
- 'List' is from 'dart:core'.
- 'Future' is from 'dart:async'. Future countries=[];
How can I resolve this issue?
>' can't be assigned to the parameter type 'Future
– Phil Cleland May 06 '22 at 08:09>?'. - 'List' is from 'dart:core'. - 'Future' is from 'dart:async'. future: countries,