我有两个飞镖页。[1]:https ://i.stack.imgur.com/D1xaf.png
在第二页中,我从网站上抓取了文本并将值存储在一个名为的字符串中,并使用命令在控制台命令行fetchedstring
中打印字符串。print
但我希望这个字符串显示在我的主要飞镖页面中。
怎么做?
//DART FILE 1 HAS THE FOLLOWING CODE
import 'package:flutter/material.dart';
import './function.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget
{
@override
Widget build(BuildContext context)
{
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(),
body: new Center(
child: new String(fetchedtext),//Here I Want The Fetched Text
),
),
);
}
}
//DART PAGE 2 HAS THE FOLLOWING CODE
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as parser;
import 'package:html/dom.dart';
mainz() async
{
http.Response response = await http.get('https://www.google.com');
Document document = parser.parse(response.body);
document.getElementsByTagName('a').forEach((Element element)
{
final String fetchedText = element.text;
print(fetchedText);
}
);
}
//I WANT THAT String "fetchedtext" to be displayed in my Dart Page1.