未处理的异常:MissingPluginException(在通道sms_autofill上未找到方法listenForCode的实现)

时间:2020-07-24 03:11:03

标签: android-studio flutter dart package flutter-dependencies

我正在研究一个项目,在与队友合并代码之前,包 sms_autofill 可以正常运行,但是在代码合并之后,我已经运行了 flutter clean ,但仍然显示两个错误,如下所示:

Unhandled Exception: MissingPluginException(No implementation found for method listenForCode on channel sms_autofill)

Unhandled Exception: MissingPluginException(No implementation found for method getAppSignature on channel sms_autofill)

我的代码:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:rentto_tenant/model/auth.dart';
import 'package:rentto_tenant/repository/auth_repository.dart';
import 'package:rentto_tenant/util/exception/ResponseException.dart';
import 'package:rentto_tenant/view/welcome/welcome.dart';
import 'package:rentto_tenant/view/home/home.dart';
import 'package:rentto_tenant/widget/loaders/color_loader_3.dart';
import 'package:rentto_tenant/widget/loaders/color_loader_4.dart';
import 'package:rentto_tenant/widget/loading_widget.dart';
import 'package:sms_autofill/sms_autofill.dart';
import 'package:pin_code_text_field/pin_code_text_field.dart';

import '../../constant/color.dart';
import '../../constant/dimen.dart';

class SMSVerificationPage extends StatefulWidget {
  final String uuid;
  final String phoneNumber;
  final String password;
  final String requestType;

  const SMSVerificationPage(
      {Key key, this.uuid, this.phoneNumber, this.password, this.requestType})
      : super(key: key);

  @override
  _SMSVerificationPageState createState() => _SMSVerificationPageState();
}

class _SMSVerificationPageState extends State<SMSVerificationPage>
    with CodeAutoFill {
  TextEditingController pinCodeController = new TextEditingController();
  TextEditingController autoFillCodeController = new TextEditingController();

  _resendCode() async {
    _loadingController.startLoading();
    try {
      String _uuid =
          await AuthUserRepository.of(context).resendCode(widget.phoneNumber);
      _loadingController.stopLoading();
      setState(() {
        _codeResent = true;
        _codeExpiresInXMin = 5;
      });
      startTimer();
      print(_uuid);
    } on ResponseException catch (e) {
      print(e.response.statusCode);
      print(e.response.body);
    } catch (e) {
      print(e.toString());
    } finally {
      _loadingController.stopLoading();
    }
  }

  _verifyCode() async {
    _loadingController.startLoading();
    try {
      AuthUser auth = await AuthUserRepository.of(context).verifyUser(
          widget.uuid,
          pinCodeController.text,
          widget.password,
          widget.requestType);
      // store Auth Tokens
      print(auth.toJson());
      // navigate
      _loadingController.stopLoading();
      if (widget.requestType == "reset_password") {
        Navigator.of(context).pushAndRemoveUntil(
            MaterialPageRoute(builder: (context) => HomePage()),
            (route) => false);
      } else {
        Navigator.of(context).pushAndRemoveUntil(
            MaterialPageRoute(builder: (context) => WelcomePage()),
            (route) => false);
      }
    } on ResponseException catch (e) {
      _codeErr = true;
      print(e.response.statusCode);
      print(e.response.body);
    } catch (e) {
      _codeErr = true;
      print(e.toString());
      throw (e);
    } finally {
      _loadingController.stopLoading();
    }
  }

  String appSignature;
  String otpCode;

  bool _codeErr = false;
  bool _codeResent = false;

  Timer _timer;
  int _codeExpiresInXMin = 5;

  void startTimer() {
    const oneMin = const Duration(minutes: 1);
    _timer = new Timer.periodic(
      oneMin,
      (Timer timer) => setState(
        () {
          if (_codeExpiresInXMin < 1) {
            timer.cancel();
          } else {
            _codeExpiresInXMin = _codeExpiresInXMin - 1;
          }
        },
      ),
    );
  }

  @override
  void codeUpdated() {
    setState(() {
      otpCode = code;
      pinCodeController.text = code;
    });
  }

  @override
  void initState() {
    startTimer();
    listenForCode();
    SmsAutoFill().getAppSignature.then((signature) {
      setState(() {
        appSignature = signature;
      });
    });
    super.initState();
  }

  @override
  void dispose() {
    _timer.cancel();
    cancel();
    super.dispose();
  }

  final _loadingController = LoadingController();

  @override
  Widget build(BuildContext context) {
    return LoadingWidget(
      controller: _loadingController,
      child: Scaffold(
        body: SafeArea(
          child: SingleChildScrollView(
            child: Center(
              child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(top: 15.0, bottom: 8.0),
                          child: Image(
                            image: AssetImage(
                              "assets/images/Logo.png",
                            ),
                            width: 93,
                            height: 110,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(bottom: 30),
                          child: Text(
                            "RENTTO",
                            style: Theme.of(context).textTheme.headline4.copyWith(
                                  color: AppColors.genericColor,
                                ),
                            textAlign: TextAlign.center,
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.all(10.0),
                          child: Text(
                            "Enter Verifcation code",
                            textAlign: TextAlign.center,
                            style: Theme.of(context).textTheme.headline5,
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 10.0),
                          child: Text(
                            "If you're having any issue, contact to RENTTO",
                            textAlign: TextAlign.center,
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 40, bottom: 25),
                          child: PinCodeTextField(
                            controller: pinCodeController,
                            maxLength: 6,
                            pinBoxWidth: 50,
                            pinBoxHeight: 50,
                            pinBoxRadius: 10,
                            pinBoxBorderWidth: 1,
                            autofocus: true,
                            highlight: true,
                            highlightColor: AppColors.genericColor,
                            hasError: _codeErr,
                            errorBorderColor: Colors.red,
                            pinTextStyle: TextStyle(
                                color: AppColors.genericColor,
                                fontSize: 25,
                                fontWeight: FontWeight.bold),
                            keyboardType: TextInputType.number,
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 15),
                          child: _codeResent
                              ? Text(
                                  'OTP Code has been resent! Please fill in the code in ' +
                                      _codeExpiresInXMin.toString() +
                                      ' minutes.',
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: AppColors.genericColor,
                                  ),
                                  textAlign: TextAlign.center,
                                )
                              : Text(
                                  'OTP Code has been sent! Please check your message and fill in the code in ' +
                                      _codeExpiresInXMin.toString() +
                                      ' minutes.',
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: AppColors.genericColor,
                                  ),
                                  textAlign: TextAlign.center,
                                ),
                        ),
                        FlatButton(
                          onPressed: () {
                            setState(() {
                              _loadingController.startLoading();
                            });
                            _resendCode();
                          },
                          child: Text("Resend Code",
                              style: TextStyle(
                                  fontSize: 17,
                                  color: AppColors.genericColor,
                                  fontWeight: FontWeight.w600)),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 30.0, bottom: 30.0),
                          child: RaisedButton(
                            padding: EdgeInsets.symmetric(
                                horizontal: 120, vertical: 15),
                            onPressed: () {
                              setState(() {
                                _loadingController.startLoading();
                              });
                              _verifyCode();
                            },
                            child: Text(
                              "CONTINUE",
                              style: TextStyle(
                                fontSize: AppDimens.btnTextSize,
                              ),
                            ),
                            color: AppColors.primaryColors,
                          ),
                        )
                      ],
                    ),
            ),
          ),
        ),
      ),
    );
  }
}

颤抖的医生-v:

    [✓] Flutter (Channel master, 1.21.0-6.0.pre.3, on Linux, locale en_US.UTF-8)
    • Flutter version 1.21.0-6.0.pre.3 at /home/veasnawt/Flutter/flutter
    • Framework revision ddb8e6e3bf (24 hours ago), 2020-07-22 20:00:07 -0700
    • Engine revision dcc9a4048d
    • Dart version 2.9.0 (build 2.9.0-21.0.dev 9dca49e71e)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/veasnawt/Android/Sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /snap/android-studio/90/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 3.6)
    • Android Studio at /snap/android-studio/88/android-studio
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Android Studio (version 4.0)
    • Android Studio at /snap/android-studio/90/android-studio
    • Flutter plugin version 47.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (4 available)
    • AOSP on IA Emulator (mobile) • emulator-5554 • android-x86    • Android 9 (API 28) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Linux
    • Web Server (web)             • web-server    • web-javascript • Flutter Tools
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 81.0.4044.129

• No issues found!

pubspec.yaml:

name: rentto_tenant
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  flutter_i18n: ^0.18.0
  json_annotation: ^3.0.1
  http: ^0.12.2
  provider: ^4.3.1
  flutter_dotenv: ^2.1.0
  pin_code_text_field: ^1.2.1
  sms_autofill: ^1.2.1
  font_awesome_flutter: ^8.8.1
  flutter_facebook_login: ^3.0.0
  intro_slider: ^2.3.1
  fluttertoast: ^7.0.1
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^1.10.0
  json_serializable: ^3.3.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - .env
    - assets/images/
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

我不知道这是怎么回事,我曾尝试在互联网上搜索,但似乎没有与此相关的解决方案。 enter code here

1 个答案:

答案 0 :(得分:0)

最后,我知道问题出在哪里。

软件包sms_autofill本身不是问题的原因,问题在于软件包flutter_facebook_login已安装且未使用。删除或正确使用它可以解决问题。