美文网首页Flutter中文社区Flutter圈子
Flutter 常见问题及其解决方案,持续更新...

Flutter 常见问题及其解决方案,持续更新...

作者: 窗外的雪儿飞 | 来源:发表于2019-05-25 00:07 被阅读0次

1. Waiting for another flutter command to release the startup lock...

// 杀死dart进程
flutter packages pub build_runner watch

// 终极方案,删除flutter SDK文件夹目录下的bin/cache下边的lockfile文件
rm ./flutter/bin/cache/lockfile

2. Could not find a file named "pubspec.yaml" in https://github.com/MarkOSullivan94/dart_config.git 7a88fbc5fd987dce78e468ec45e9e841a49f422d.

// 删除flutter SDK文件夹目录下的.pub-cache下边的git文件夹
rm ./flutter/.pub-cache/git

3.点击任意空白处,软键盘收起

GestureDetector(
    /// 透明也响应处理
    behavior: HitTestBehavior.translucent,
    onTap: () {
      /// 触摸收起键盘
      FocusScope.of(context).requestFocus(FocusNode());
    },
    child: Container(
       /// xxx
    ),
);

4. Oops; flutter has exited unexpectedly. Sending crash report to Google.

/// 在终端执行命令
xcode-select --install

5. 页面返回隐藏虚拟导航条

@override
void deactivate() {
    SystemChrome.restoreSystemUIOverlays();
    super.deactivate();
}

6. 如果没有网络连接,如何启动静态html页面而不是URL ?【webview】

Future check() async {
    try {
      final result = await InternetAddress.lookup('google.com');
      if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        connectionStatus = true;
        print("connected $connectionStatus");
      }
    } on SocketException catch (_) {
      connectionStatus = false;
      print("not connected $connectionStatus");
    }
}

FutureBuilder(
    future: check(),
    builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
      if (connectionStatus == true) {
        /// 如果网络正常连接
        return SafeArea(
            child: WebviewScaffold(
                url: "http://www.baidu.com",
            ),
        ),
      } else { 
        /// 如果网络连接失败
        return SafeArea(
            child: WebviewScaffold(
              url: Uri.dataFromString('<html><body>hello world</body></html>',
              mimeType: 'text/html').toString()
            ),
        ),
      }
    }
)

相关文章

网友评论

    本文标题:Flutter 常见问题及其解决方案,持续更新...

    本文链接:https://www.haomeiwen.com/subject/exbozqtx.html