【问题标题】:how to show a dialog on the splashscreen using RFlutter Alert or just pop up dialog and exit if there is no wifi如何使用 RFlutter Alert 在启动画面上显示对话框,或者在没有 wifi 的情况下弹出对话框并退出
【发布时间】:2020-01-16 10:51:07
【问题描述】:

抱歉,我刚开始学习 Flutter 并制作了一个简单的页面。我想检查是否有互联网,如果没有,我想在启动屏幕上使用 rFlutterPackage 显示弹出警报(如果可能)。如果我不能使用闪屏,我可以重定向到新页面并只显示对话框。

只有在按下按钮时才会触发警报对话框?

一旦用户点击警报按钮,我如何关闭应用程序?

如何使用对话框显示在初始屏幕顶部,以便用户点击?

主页

import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
import 'package:algorithm_send_location/pages/home_screen.dart';
import 'package:algorithm_send_location/pages/splash_screen.dart';
import 'package:algorithm_send_location/pages/initial_warning.dart';

var routes = <String, WidgetBuilder>{
  "/home": (BuildContext context) => HomeScreen(),
};

void main() => runApp(new MaterialApp(
    theme:
        ThemeData(primaryColor: Colors.amber, accentColor: Colors.green[200]),
    debugShowCheckedModeBanner: false,
    home: _checkConnectivity ? SplashScreen() : WarningScreen(),
    routes: routes));

get _checkConnectivity async {
  var internetResult = await Connectivity().checkConnectivity();

  if (internetResult == ConnectivityResult.none) {
    return false;
  } else if (internetResult == ConnectivityResult.wifi ||
      internetResult == ConnectivityResult.mobile) {
    return false;
    //return true;
  }
}


我想使用提醒

Alert(
      context: context,
      type: AlertType.warning,
      title: "RFLUTTER ALERT",
      desc: "Flutter is more awesome with RFlutter Alert.",
      buttons: [
        DialogButton(
          child: Text(
            "There is no internet Connection",
            style: TextStyle(color: Colors.white, fontSize: 20),
          ),
          onPressed: () => Navigator.pop(context),
          color: Color.fromRGBO(0, 179, 134, 1.0),
        ),

      ],
    ).show();

【问题讨论】:

    标签: flutter


    【解决方案1】:

    我建议不要在可能导致您出现问题的页面之前创建对话框。只需在您的应用中创建整页消息即可。在那里,您可以为退出和重试输入代码。这将更加用户友好,而不会破坏应用程序中的任何内容。

    要查看网络的实时状态,您可以使用Connectivity Package

    退出应用程序使用

    SystemChannels.platform.invokeMethod('SystemNavigator.pop');

    阅读here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 2013-06-15
      相关资源
      最近更新 更多