“未来”的实例<String>

问题描述 投票:0回答:1

这是我未来的职能。

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');
 }
}

这是我显示信息的地方

 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.
);
}


}

我使用 flutter_html 包来解析调用 api 时获得的 html 并将其显示在我的应用程序中,但它没有显示,而是我在我的应用程序上得到 FutureBuilder

你能帮我吗? enter image description here

enter image description here

调试控制台

flutter-html
1个回答
0
投票

你找到答案了吗?我也有同样的问题...

© www.soinside.com 2019 - 2024. All rights reserved.