Flutter应用在启动时崩溃“连接服务协议时出错”

时间:2019-08-04 02:37:48

标签: flutter dart

我知道其他人已发布有关此问题的信息,但是没有一种解决方案对我有用。现在已经进行了大约4个小时的故障排除/研究,没有运气...

每当我尝试在ios终端上执行“ flutter run”命令(或仅从vs代码运行)时,应用程序启动,然后在最初的几秒钟内崩溃,提示我“连接到服务协议时出错”错误消息

  • 重置xcode模拟器

  • 正在运行iphone X sim的较早版本(12.0)(以及苹果生态系统中的其他手机)

  • 按照与此类似的其他帖子中的建议,在.bash_profile中添加“ NO_PROXY = localhost,127.0.0.1”。

这是我认为如果与代码无关而不与模拟器相关的代码,可能会导致错误。请注意,某些数据并不重要,而只是诸如本地数组数据之类的填充物。

class _MyAppState extends State<MyApp> {
//-----------------Variables--------------------
  final PageController ctrl = PageController();
  List<String> local = ['1', '2', '3']; //fill with events in your area
//----------------------------------------------
  @override

  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            body: PageView(
      scrollDirection: Axis.horizontal,
      controller: ctrl,
      children: <Widget>[
        StreamBuilder(
            stream: Firestore.instance.collection('local').snapshots(),
            builder: (context, snapshot) {
              if (!snapshot.hasData)
                return const Text('Loading...');
              else {
                return ListView.builder(
                  itemCount: snapshot.data.documents.length,
                  itemBuilder: (context, index) {
                    DocumentSnapshot userPost = snapshot.data.documents[index];
                    return Container(
                      width: MediaQuery.of(context).size.width,
                      height: 350.0,
                      child: Padding(
                          padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
                          child: Material(
                            color: Colors.white,
                            elevation: 14.0,
                            shadowColor: Color(0x802196f3),
                            child: Center(
                              child: Padding(
                                  padding: EdgeInsets.all(8.0),
                                  child: Column(
                                    children: <Widget>[
                                      Container(
                                          width:
                                              MediaQuery.of(context).size.width,
                                          height: 200.0,
                                          child: Image.network(
                                            '${userPost['image']}',
                                            fit: BoxFit.fill,
                                          )),
                                      SizedBox(height: 10.0),
                                      Text('${userPost['title']}',
                                          style: TextStyle(
                                              fontSize: 20.0,
                                              fontWeight: FontWeight.bold)),

预计将显示一张显示消防站数据的卡,但得到此终端响应:

Configuring the default Firebase app...
6.1.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
6.1.0 - [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
6.1.0 - [Firebase/Core][I-COR000005] No app has been configured yet.
6.1.0 - [Firebase/Core][I-COR000005] No app has been configured yet.
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010904029b __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x00000001085dc735 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001090400f5 +[NSException raise:format:] + 197
    3   Runner                              0x0000000102cf5f42 +[FIRApp configure] + 562
    4   Runner                              0x0000000103244c66 -[FLTCloudFirestorePlugin init] + 214
    5   Runner                              0x0000000103244a6c +[FLTCloudFirestorePlugin registerWithRegistrar:] + 300
    6   Runner                              0x0000000102baa360 +[GeneratedPluginRegistrant registerWithRegistry:] + 112
    7   Runner                        <…>
Error connecting to the service protocol: HttpException: , uri =
http://127.0.0.1:50250/IGi9jQDg97Q=/ws

1 个答案:

答案 0 :(得分:0)

对于Android, 您是否已在android清单文件中添加了互联网权限?。

<uses-permission android:name="android.permission.INTERNET"/>

对于iOS,

在Info.plist中

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>