它不会从初始加载屏幕显示(无限加载或freze)

问题描述 投票:0回答:1

它没有从初始加载屏幕中消失...

运行时

D/FlutterActivity( 1126): Using the launch theme as normal theme.<br />
D/FlutterActivityAndFragmentDelegate( 1126): Setting up FlutterEngine.<br />
D/FlutterActivityAndFragmentDelegate( 1126): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.<br />
D/FlutterActivityAndFragmentDelegate( 1126): Attaching FlutterEngine to the Activity that owns this Fragment.<br />
D/FlutterView( 1126): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@2227296<br />
D/FlutterActivityAndFragmentDelegate( 1126): Executing Dart entrypoint: main, and sending initial route: /<br />
E/flutter ( 1126): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.<br />
E/flutter ( 1126): If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.<br />
E/flutter ( 1126): If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.<br />
E/flutter ( 1126): #0      defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:76:7)<br />
E/flutter ( 1126): #1      defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:89:4)<br />
E/flutter ( 1126): #2      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)<br />
E/flutter ( 1126): #3      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:35)<br />
E/flutter ( 1126): #4      OptionalMethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:429:36)<br />
E/flutter ( 1126): #5      SystemChrome.setPreferredOrientations (package:flutter/src/services/system_chrome.dart:236:35)<br />
E/flutter ( 1126): #6      main (package:aciel_pro/main.dart:8:16)<br />
E/flutter ( 1126): #7      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:239:25)<br />
E/flutter ( 1126): #8      _rootRun (dart:async/zone.dart:1126:13)<br />
E/flutter ( 1126): #9      _CustomZone.run (dart:async/zone.dart:1023:19)<br />
E/flutter ( 1126): #10     _runZoned (dart:async/zone.dart:1518:10)<br />
E/flutter ( 1126): #11     runZoned (dart:async/zone.dart:1502:12)<br />
E/flutter ( 1126): #12     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:231:5)<br />
E/flutter ( 1126): #13     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)<br />
E/flutter ( 1126): #14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)<br />
E/flutter ( 1126):<br />
D/FlutterActivity( 1126): Using the launch theme as normal theme.<br />
D/FlutterActivityAndFragmentDelegate( 1126): Setting up FlutterEngine.<br />
D/FlutterActivityAndFragmentDelegate( 1126): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.<br />
D/FlutterActivityAndFragmentDelegate( 1126): Attaching FlutterEngine to the Activity that owns this Fragment.<br />
D/FlutterView( 1126): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@2227296<br />
D/FlutterActivityAndFragmentDelegate( 1126): Executing Dart entrypoint: main, and sending initial route: /<br />
E/flutter ( 1126): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.<br />
E/flutter ( 1126): If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.<br />
E/flutter ( 1126): If you're running a test, you can call the 'TestWidgetsFlutterBinding.ensureInitialized'() as the first line in your test's `main()` method to initialize the binding.<br />
E/flutter ( 1126): #0      defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:76:7)<br />
E/flutter ( 1126): #1      defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:89:4)<br />
E/flutter ( 1126): #2      MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)<br />
E/flutter ( 1126): #3      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:35)<br />
E/flutter ( 1126): #4      OptionalMethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:429:36)<br />
E/flutter ( 1126): #5      SystemChrome.setPreferredOrientations (package:flutter/src/services/system_chrome.dart:236:35)<br />
E/flutter ( 1126): #6      main (package:aciel_pro/main.dart:8:16)<br />
E/flutter ( 1126): #7      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:239:25)<br />
E/flutter ( 1126): #8      _rootRun (dart:async/zone.dart:1126:13)<br />
E/flutter ( 1126): #9      _CustomZone.run (dart:async/zone.dart:1023:19)<br />
E/flutter ( 1126): #10     _runZoned (dart:async/zone.dart:1518:10)<br />
E/flutter ( 1126): #11     runZoned (dart:async/zone.dart:1502:12)<br />
E/flutter ( 1126): #12     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:231:5)<br />
E/flutter ( 1126): #13     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)<br />
E/flutter ( 1126): #14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)<br />`

主要

import 'package:aciel_pro/screens/loginpage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import'./screens/getting_started_screen.dart';

void main() {
  SystemChrome.setPreferredOrientations ( [DeviceOrientation.portraitUp] )
      .then ((_) {
    runApp (MyApp());
  });
}

class MyApp extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title:'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: GettingStartedScreen(),
      routes:{
        LoginPage.routeName: (ctx) => LoginPage(),
      }
    );
  }
 }

loginPage

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:aciel_pro/services/authservice.dart';

class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final formKey = new GlobalKey<FormState>();

  String phoneNo,verificationId, smsCode;

  bool codeSent = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Form(
        key: formKey,
          child:Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(left: 25.0, right: 25.0),
                child:TextField(
                  keyboardType: TextInputType.phone,
                  decoration: InputDecoration(hintText: '전화번호인증'),
                  onChanged: (val) {
                    setState(() {
                      this.phoneNo = val;
                    });
                  },
                )),
              codeSent ? Padding(
                  padding: EdgeInsets.only(left: 25.0, right: 25.0),
                  child:TextField(
                    keyboardType: TextInputType.phone,
                    decoration: InputDecoration(hintText: 'Enter OTP'),
                    onChanged: (val) {
                      setState(() {
                        this.smsCode = val;
                      });
                    },
                  )) : Container(),
              Padding(
            padding: EdgeInsets.only(left: 25.0, right: 25.0),
            child: RaisedButton(
              child: Center(child: codeSent ? Text('Login'):Text('인증하기')),
            onPressed: () {
              codeSent ? AuthService().signInWithOTP(smsCode, verificationId):verifyPhone(phoneNo);
            }))
        ],
      )),
      );
}
Future<void> verifyPhone(phoneNo) async {

final PhoneVerificationCompleted verified = (AuthCredential authResult) {
  AuthService(). signIn(authResult);
};

final PhoneVerificationFailed verificationFailed = (AuthException authException) {
  print('${authException.message}');
};

final PhoneCodeSent smsSent = (String verId, [int forceResend]) {
  this.verificationId = verId;
  setState(() {
    this.codeSent = true;
  });
};

final PhoneCodeAutoRetrievalTimeout autoTimeout = (String verId) {
  this.verificationId = verId;
};

await FirebaseAuth. instance. verifyPhoneNumber(
    phoneNumber: phoneNo,
    timeout: const Duration(seconds: 5),
    verificationCompleted: verified,
    verificationFailed: verificationFailed,
    codeSent: smsSent,
    codeAutoRetrievalTimeout: autoTimeout);
  }
}

#getting_stared_screen#


import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:aciel_pro/services/authservice.dart';

class LoginPage extends StatefulWidget {
  static const routeName ='/login';
@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final formKey = new GlobalKey<FormState>();

  String phoneNo,verificationId, smsCode;

  bool codeSent = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Form(
        key: formKey,
          child:Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
            Padding(
            padding: EdgeInsets.only(left: 25.0, right: 25.0),
            child:TextField(
              keyboardType: TextInputType.phone,
              decoration: InputDecoration(hintText: '전화번호인증'),
              onChanged: (val) {
                setState(() {
                  this.phoneNo = val;
                });
              },
            )),
          codeSent ? Padding(
              padding: EdgeInsets.only(left: 25.0, right: 25.0),
              child:TextField(
                keyboardType: TextInputType.phone,
                decoration: InputDecoration(hintText: 'Enter OTP'),
                onChanged: (val) {
                  setState(() {
                    this.smsCode = val;
                  });
                },
              )) : Container(),
          Padding(
            padding: EdgeInsets.only(left: 25.0, right: 25.0),
            child: RaisedButton(
              child: Center(child: codeSent ? Text('Login'):Text('인증하기')),
            onPressed: () {
              codeSent ? AuthService().signInWithOTP(smsCode, verificationId):verifyPhone(phoneNo);
            }))
        ],
      )),
    );
  }

  Future<void> verifyPhone(phoneNo) async {

    final PhoneVerificationCompleted verified = (AuthCredential authResult) {
      AuthService(). signIn(authResult);
    };

final PhoneVerificationFailed verificationFailed = (AuthException authException) {
  print('${authException.message}');
};

final PhoneCodeSent smsSent = (String verId, [int forceResend]) {
  this.verificationId = verId;
  setState(() {
    this.codeSent = true;
  });
};

final PhoneCodeAutoRetrievalTimeout autoTimeout = (String verId) {
  this.verificationId = verId;
};

await FirebaseAuth. instance. verifyPhoneNumber(
    phoneNumber: phoneNo,
    timeout: const Duration(seconds: 5),
    verificationCompleted: verified,
    verificationFailed: verificationFailed,
    codeSent: smsSent,
    codeAutoRetrievalTimeout: autoTimeout);
  }
}






dashbored :


import 'package:flutter/material.dart';
import 'package:aciel_pro/services/authservice.dart';

class Dashboardpage extends StatefulWidget {
  @override
  _DashbordPageState createState() => _DashbordPageState();
}

class _DashbordPageState extends State<Dashboardpage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child:RaisedButton(
          child: Text('Signout'),
          onPressed: () {
            AuthService().signOut();
          },
        )
      ),
    );
  }    
}

帮助...短知识不会解决。应用程序的操作结构

应用程序启动>加载>主屏幕(splashscreen&selectlogin)> loginauth(SMSauth)>主页

android flutter flutter-layout helper flutter-test
1个回答
0
投票

您只需添加此代码即可解决问题

WidgetsFlutterBinding.ensureInitialized();

之前;

SystemChrome.setPreferredOrientations ( [DeviceOrientation.portraitUp] )
      .then ((_) {
    runApp (MyApp());
  });

最后应该是这样;

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  SystemChrome.setPreferredOrientations ( [DeviceOrientation.portraitUp] )
      .then ((_) {
    runApp (MyApp());
  });
}
© www.soinside.com 2019 - 2024. All rights reserved.