在Google登录后发送消息后屏幕冻结(Flutter Firebase Codelab Friendly Chat App)

我已经完成了这段代码的flutter firebase

应用程序加载正常,接受输入,然后加载Google登录选项(如果尚未登录,则添加帐户) . 在此之后,应用程序冻结 .

以下是抛出异常的一些屏幕截图:message_codecs.dart第514行

抛出新的PlatformException(代码:errorCode,message:errorMessage,details:errorDetails);

使用新的Flutter插件运行模拟器的Android Studio的屏幕截图:
AndroidStudioFlutterPluginEmulatorRuntimeOutput

在实际的Nexus 5手机上运行时的屏幕截图:
AndroidStudioFlutterPhoneError

这是main.dart:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'dart:async';

const String _name = "GCom";
final googleSignIn = new GoogleSignIn();
final ThemeData kIOSTheme = new ThemeData(
  primarySwatch: Colors.orange,
  primaryColor: Colors.grey[100],
  primaryColorBrightness: Brightness.light,
);
final ThemeData kDefaultTheme = new ThemeData(
  primarySwatch: Colors.red,
  accentColor: Colors.orangeAccent[400],
);

void main() {
  runApp(new FriendlychatApp());
}

Future<Null> _ensureLoggedIn() async {
  GoogleSignInAccount user = googleSignIn.currentUser;
  if (user == null) user = await googleSignIn.signInSilently();
  if (user == null) {
    await googleSignIn.signIn();
  }
}

class FriendlychatApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "friendly chatty patch",
      theme: defaultTargetPlatform == TargetPlatform.android
          ? kDefaultTheme
          : kIOSTheme,
      home: new ChatScreen(),
    );
  }
}

class ChatMessage extends StatelessWidget {
  ChatMessage({this.text, this.animationController});
  final String text;
  final AnimationController animationController;

  @override
  Widget build(BuildContext context) {
    return new SizeTransition(
        sizeFactor: new CurvedAnimation(
            parent: animationController, curve: Curves.easeOut),
        axisAlignment: 0.0,
        child: new Container(
          margin: const EdgeInsets.symmetric(
              vertical: 15.0), //10 vertical depth from top of screen. height.
          child: new Row(
            crossAxisAlignment:
                CrossAxisAlignment.start, //distance vertical of avatar icon
            children: <Widget>[
              new Container(
                  margin: const EdgeInsets.only(
                      right: 16.0), //0-36- move r of Icon  orig 16
                  child: new CircleAvatar(
                      backgroundImage:
                          new NetworkImage(googleSignIn.currentUser.photoUrl))),
              new Column(
                crossAxisAlignment: CrossAxisAlignment
                    .end, //.start brings _name end to end of text vertical
                children: <Widget>[
                  new Text(googleSignIn.currentUser.displayName, //_name
                      style: Theme.of(context).textTheme.subhead), //headline
                  new Container(
                      margin: const EdgeInsets.only(
                          top: 5.0), //distance under _name 40
                      child: new Text(text +
                          "  whenever") // style: Theme.of(context).textTheme.subhead),
                      ),
                ],
              ),
            ],
          ),
        ));
  }
}

class ChatScreen extends StatefulWidget {
  @override
  State createState() => new ChatScreenState();
}

class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
  final List<ChatMessage> _messages = <ChatMessage>[];
  final TextEditingController _textController = new TextEditingController();
  bool _isComposing = false;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        //can be different than title?
        appBar: new AppBar(
          title: new Text("friendly chatty patchy codelab."),
          elevation:
              Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 4.0,
        ),
        body: new Container(
            child: new Column(children: <Widget>[
          new Flexible(
              child: new ListView.builder(
            padding: new EdgeInsets.all(8.0),
            reverse: false, //true to place at bottom of screen.
            itemBuilder: (_, int index) => _messages[index],
            itemCount: _messages.length,
          )),
          new Divider(height: 1.0),
          new Container(
            decoration: new BoxDecoration(color: Theme.of(context).cardColor),
            child: _buildTextComposer(),
          ),
        ]))); //extra )?
  }

  @override
  Widget _buildTextComposer() {
    return new IconTheme(
      data: new IconThemeData(color: Theme.of(context).accentColor),
      child: new Container(
          margin: const EdgeInsets.symmetric(horizontal: 8.0), //distance from r
          child: new Row(children: <Widget>[
            new Flexible(
              child: new TextField(
                controller: _textController,
                onChanged: (String text) {
                  setState(() {
                    _isComposing = text.length > 2; //>0
                  });
                },
                onSubmitted: _handleSubmitted,
                decoration: new InputDecoration.collapsed(
                    hintText: "send a message..."),
              ),
            ),
            new Container(
                margin: new EdgeInsets.symmetric(horizontal: 4.0),
                child: Theme.of(context).platform == TargetPlatform.iOS
                    ? new CupertinoButton(
                        child: new Text("Send"),
                        onPressed: _isComposing
                            ? () => _handleSubmitted(_textController.text)
                            : null,
                      )
                    : new IconButton(
                        icon: new Icon(Icons.send), //whatever icon
                        onPressed: _isComposing
                            ? () => _handleSubmitted(_textController.text)
                            : null,
                      )),
          ]),
          decoration: Theme.of(context).platform == TargetPlatform.iOS
              ? new BoxDecoration(
                  border:
                      new Border(top: new BorderSide(color: Colors.grey[200])))
              : null),
    );
  }

  Future<Null> _handleSubmitted(String text) async {
    _textController.clear();
    setState(() {
      _isComposing = false;
    });
    await _ensureLoggedIn();
    // ignore: referenced_before_declaration
    void _sendMessage({String text}) {
      ChatMessage message = new ChatMessage(
        text: text,
        animationController: new AnimationController(
          duration: new Duration(milliseconds: 1000),
          vsync: this,
        ),
      );
      setState(() {
        _messages.insert(0, message);
      });
      message.animationController.forward();
    }

    _sendMessage(text: text);
  }

  @override
  void dispose() {
    for (ChatMessage message in _messages)
      message.animationController.dispose();
    super.dispose();
  }
}

Android监视器显示该应用正在加载,启动Google登录 . 只有当我点击谷歌帐户时才会出现'未知缓冲区' .

20 13:15:39.403 3342-3367/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-20 13:15:39.468 3342-3367/? I/OpenGLRenderer: Initialized EGL, version 1.4

                                                 [ 10-20 13:15:39.469  3342: 3367 D/         ]
                                                 HostConnection::get() New Host Connection established 0x7f629efd1ea0, tid 3367


                                                 [ 10-20 13:15:39.470  3342: 3367 W/         ]
                                                 Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 
10-20 13:15:39.470 3342-3367/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
10-20 13:15:39.482 3342-3367/? D/EGL_emulation: eglCreateContext: 0x7f629efe2220: maj 2 min 0 rcv 2
10-20 13:15:39.489 3342-3367/? D/EGL_emulation: eglMakeCurrent: 0x7f629efe2220: ver 2 0 (tinfo 0x7f629f08ec60)
10-20 13:15:39.504 3342-3367/? D/EGL_emulation: eglMakeCurrent: 0x7f629efe2220: ver 2 0 (tinfo 0x7f629f08ec60)
10-20 13:15:39.519 3342-3342/? D/EGL_emulation: eglCreateContext: 0x7f629b407b20: maj 2 min 0 rcv 2
10-20 13:15:39.533 3342-3342/? D/EGL_emulation: eglMakeCurrent: 0x7f629b407b20: ver 2 0 (tinfo 0x7f629b38bfa0)
10-20 13:15:39.632 3342-3361/? D/EGL_emulation: eglMakeCurrent: 0x7f629b407b20: ver 2 0 (tinfo 0x7f629b38bee0)
10-20 13:15:39.635 3342-3368/? I/flutter: Diagnostic server listening on http://127.0.0.1:35653/
10-20 13:15:39.719 3342-3368/? I/flutter: Observatory listening on http://127.0.0.1:45464/
10-20 13:16:16.163 3342-3367/com.yourcompany.gcodelab D/EGL_emulation: eglMakeCurrent: 0x7f629efe2220: ver 2 0 (tinfo 0x7f629f08ec60)
10-20 13:16:23.166 3342-3367/com.yourcompany.gcodelab D/EGL_emulation: eglMakeCurrent: 0x7f629efe2220: ver 2 0 (tinfo 0x7f629f08ec60)
10-20 13:16:23.166 3342-3367/com.yourcompany.gcodelab E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f629efe1640

回答(1)

2 years ago

我认为如果未启用Google登录(可以在Firebase控制台或here中完成),或者用于签署APK的公钥的哈希没有上传到Firebase控制台,或者应用程序标识符(如果例如,com.example.myapp)未在Firebase控制台中正确设置 . 我建议检查这三件事,以确保他们没有看到任何有用的控制台日志 .