android - 有没有办法在颤动的android应用程序屏幕上打印调试或控制台消息?
问题描述
我正在构建一个登录页面,当没有验证邮件时,用户将显示在未验证邮件的屏幕上,这是我尝试做的以下代码。
if(user.isEmailVerified == false){
print('Email not verified') //in console screen
return Text('Please verify email') // in android screen
}
但是没有任何结果, 假设没有语法错误有没有办法在屏幕上显示字符串?我什至尝试使用新容器并这样做,但没有成功。
解决方案
您可以在下面复制粘贴运行完整代码
您可以使用包https://pub.dev/packages/flushbar
代码片段
RaisedButton(
onPressed: () {
Flushbar(
title: "Error",
message: "Please verify email",
duration: Duration(seconds: 10),
)..show(context);
},
child:
const Text('Enabled Button', style: TextStyle(fontSize: 20)),
),
工作演示
完整代码
import 'package:flutter/material.dart';
import 'package:flushbar/flushbar.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
Flushbar(
title: "Error",
message: "Please verify email",
duration: Duration(seconds: 10),
)..show(context);
},
child:
const Text('Enabled Button', style: TextStyle(fontSize: 20)),
),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
推荐阅读
- scala - spark submit - 现有连接被远程主机强行关闭 [在主节点上]
- python-3.x - 为什么Python在每次for循环迭代后不直接写入文件
- python - 在 MongoDB 中,如何根据一个字段是否存在和另一个字段不存在来查找文档?
- python - Vpython 使用 Spyder:如何防止浏览器选项卡打开?
- sql - SQL 按日期查询
- dart - 列表视图和其他小部件之间的巨大空间
- python-3.x - 需要一个类似字节的对象,而不是 '_io.BufferedReader'
- json - 如何存储来自 kafka 的 JSONLines RDD 消息
- android - 带有可变数量选项卡的 BottomSheet 内的 ViewPager 会导致奇怪的行为。可能有什么问题?
- mysql - MySQL LEFT JOIN 不为丢失的行返回 NULL