Instance of 'Future<String>

228 views Asked by At

This my future fuction.

Future<String> getSuburb() async {
var url =
  'https://loadshedding.eskom.co.za/LoadShedding/GetScheduleM/1062781/8/1/703';

final response = await http.get(
Uri.parse(url),
headers: {},
);

print('URL ${Uri.encodeFull(url)}');
print(response.body);
if (response.statusCode == 200) {
var document = htmlparser.parse(response.body.toString());
String body = document.getElementsByTagName('div').toString();
 print('miracle ');

return body.toString()+"what";
} else {
throw Exception('Error getting brewery');
 }
}

This is where i display the information

 class _MyHomePageState extends State<MyHomePage> {

late Future<String> futures;
void initState() {
super.initState();
futures = getSuburb();
getSuburb();
}

//String htmlCode = futures.toString();

//final String htmlCode = getSuburb().toString();
@override
Widget build(BuildContext context) {
String? htmlCode = FutureBuilder<String>(
  future: getSuburb(),
  builder: (context, AsyncSnapshot<String> snapshot) {
    if (snapshot.hasData) {
      print('miracle ');
       //print(snapshot.data);
      return Text(snapshot.data.toString());
    } else if (snapshot.hasError) {
       print('miracle ');
      return Text('what is wrong');
    }
    return const CircularProgressIndicator();
  },
).toString();
String htmlData = htmlCode;
return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: SingleChildScrollView(
    child: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          //Container(child:Text(bu().toString()),),
          SizedBox(height: 30),
          Builder(builder: (context) {
            return Container(
                padding: EdgeInsetsDirectional.all(20),
                child: Card(
                  child: Html(
                    data: htmlCode,
                  ),
                ));
          }),
          Text(htmlData)
        ],
      ),
    ),
  ),
  floatingActionButton: FloatingActionButton(
    onPressed:(){},
    tooltip: 'Increment',
    child: const Icon(Icons.add),
  ), // This trailing comma makes auto-formatting nicer for build methods.
);
}


}

Im using a flutter_html package to parse the html I get when I call the api and display it in my application but it doesn't get displayed instead I get FutureBuilder on my application

Can you help me. enter image description here

enter image description here

Debug Console

0

There are 0 answers