首页 > 解决方案 > 有没有办法在颤动的android应用程序屏幕上打印调试或控制台消息?

问题描述

我正在构建一个登录页面,当没有验证邮件时,用户将显示在未验证邮件的屏幕上,这是我尝试做的以下代码。

if(user.isEmailVerified == false){
print('Email not verified')          //in console screen
return Text('Please verify email')   // in android screen 
}

但是没有任何结果, 假设没有语法错误有没有办法在屏幕上显示字符串?我什至尝试使用新容器并这样做,但没有成功。

标签: androidflutterfirebase-authenticationscreendisplay

解决方案


您可以在下面复制粘贴运行完整代码
您可以使用包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),
      ),
    );
  }
}

推荐阅读