我想以这种方法返回 bool(boolean) 值,但它返回一个Future
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 0, right: 0, top: 110, bottom: 5),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
QuestionCards(),
cla().then((value) => { //this can't be add like this
YoutubeViewer(
videoId: 'hVQUbKs6qN8', topic: 'topic1'),
}
)
],
).
),
],
),
);
}
Future<bool> cla() async {
bool d = false;
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
return Future<bool>.value(true);
}
} on SocketException catch (_) {
print('not connected');
return Future<bool>.value(false);
}
}
如果有人可以告诉我在这方面需要更改的内容
真的很有帮助
谢谢
最佳答案
使用Future对象返回 bool(boolean) 值
return Future<bool>.value(true);
和修改方法
Future<bool> cla() async{
使用方式:
cla().then((value) {
// value will provide you true or false
});