如何创建出现在所有屏幕上的小吃店?

时间:2019-10-24 20:06:10

标签: flutter flutter-layout snackbar

我需要创建一个小吃店,当没有连接时出现, 我已经创建了一个,但是它只出现在一个屏幕上,如果没有连接,如何在所有屏幕上显示它。

在主屏幕中,我在init方法中将此称为#!/usr/local/bin/python3 from selenium import webdriver from threading import Thread all_drivers = [] class Dashboard(Thread): def __init__(self, position, url): super().__init__() self.position = position self.url = url self.driver = None def run(self): chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--window-size=100,100') chrome_options.add_argument('--start-maximized') chrome_options.add_argument(self.position) self.driver = webdriver.Chrome(options=chrome_options) self.driver.get(self.url) all_drivers.append(self.driver) pos = ['--window-position=100,100', '--window-position=1000,1000'] web = ['https://www.example.com', 'https://www.example.com'] for a, b in zip(pos, web): screen = Dashboard(a, b).start() for driver in all_drivers: driver.quit() 。它可以在主屏幕上完美运行,但是当我导航到其他屏幕时,它不会显示小吃栏。

我的支票互联网功能:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

只要您回到其他屏幕,只需使用build方法检查互联网连接即可

依赖:connectivity: 0.4.3+6

1)首选

  @override
  Widget build(BuildContext context) {

       var isConnected = await isInternetConnected();
       if (isConnected != true) {
          // Snackbar show here
       }
  }

使用此方法检查互联网连接

  Future<bool> isInternetConnected() async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.mobile ||
        connectivityResult == ConnectivityResult.wifi) {
      return true;
    }
    return false;
  }

2)第二个选择

initState()的{​​{1}}文件中添加侦听器,以便每当连接更改时您都会得到响应

main.dart