【问题标题】:Is there any way to print debug or console message in screen of android app in flutter?有没有办法在颤动的android应用程序屏幕上打印调试或控制台消息?
【发布时间】:2019-12-24 06:00:38
【问题描述】:

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

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

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

【问题讨论】:

    标签: android flutter firebase-authentication screen display


    【解决方案1】:

    您可以在下面复制粘贴运行完整代码
    你可以使用包https://pub.dev/packages/flushbar

    代码sn-p

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

    【讨论】:

      【解决方案2】:

      是的,你可以做到这一点,但不是你想的那样。你必须取名为 errorMessageString 变量并用空字符串初始化它。

      String errorMessage='';
      

      然后,您可以在包含该消息的屏幕中的任意位置使用Text()

      Text(errorMessage)
      

      然后在错误部分可以将消息设置为errorMessage变量并调用setState()

      if(user.isEmailVerified == false){
          print('Email not verified')          //in console screen
          setState((){
              errorMessage='Email Not Verified';
          });   // in android screen 
      }
      

      【讨论】:

        猜你喜欢
        • 2019-01-16
        • 2011-03-07
        • 2021-09-15
        • 1970-01-01
        • 2021-10-28
        • 2017-03-18
        • 2011-02-26
        • 2013-05-16
        • 1970-01-01
        相关资源
        最近更新 更多