NearHuscarl / flutter_login

Provides login screen with login/signup functionalities to help speed up development
MIT License
1.5k stars 799 forks source link

NoSuchMethodError after converting older project to null safety #304

Open jaredbaszler opened 2 years ago

jaredbaszler commented 2 years ago

After successful login, persistent error continues.

Error:

Error: NoSuchMethodError: ''
Dynamic call with too few arguments. Expected: 1 Actual: 0
Receiver: Instance of '(dynamic) => Null'
Arguments: []
    at Object.throw_ [as throw] (http://localhost:56379/dart_sdk.js:5063:11)
    at Object.defaultNoSuchMethod (http://localhost:56379/dart_sdk.js:5497:15)
    at Function.noSuchMethod (http://localhost:56379/dart_sdk.js:6588:19)
    at Object.noSuchMethod (http://localhost:56379/dart_sdk.js:5494:30)
    at callNSM (http://localhost:56379/dart_sdk.js:5233:19)
    at Object._checkAndCall (http://localhost:56379/dart_sdk.js:5272:12)
    at Object.dcall (http://localhost:56379/dart_sdk.js:5275:17)
at http://localhost:56379/packages/flutter_login/src/widgets/cards/auth_card_builder.dart.lib.js:3363:24
    at _RootZone.runUnary (http://localhost:56379/dart_sdk.js:40062:59)
    at _FutureListener.then.handleValue (http://localhost:56379/dart_sdk.js:34983:29)
    at handleValueCallback (http://localhost:56379/dart_sdk.js:35551:49)
    at Function._propagateToListeners (http://localhost:56379/dart_sdk.js:35589:17)
    at _Future.new.[_completeWithValue] (http://localhost:56379/dart_sdk.js:35437:23)
    at http://localhost:56379/dart_sdk.js:35378:39
    at _RootZone.runUnary (http://localhost:56379/dart_sdk.js:40062:59)
    at _FutureListener.then.handleValue (http://localhost:56379/dart_sdk.js:34983:29)
    at handleValueCallback (http://localhost:56379/dart_sdk.js:35551:49)
    at Function._propagateToListeners (http://localhost:56379/dart_sdk.js:35589:17)
    at _Future.new.[_completeWithValue] (http://localhost:56379/dart_sdk.js:35437:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:56379/dart_sdk.js:35458:35)
    at Object._microtaskLoop (http://localhost:56379/dart_sdk.js:40330:13)
    at _startMicrotaskLoop (http://localhost:56379/dart_sdk.js:40336:13)
    at http://localhost:56379/dart_sdk.js:35811:9

Expected behavior For the onSubmitAnimationCompleted event to fire and navigate to my next screen.

Information (please complete the following information):

I had recently converted to null safety. Below is my pubspec.yaml file.

name: pool_carrier_frontend
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.15.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  crypto: ^3.0.1
  cupertino_icons: ^1.0.4
  dartx: any
  date_picker_timeline: ^1.2.3
  device_info_plus: ^3.2.1
  flutter_login: ^3.1.0
  flutter_riverpod: ^1.0.3
  freezed_annotation: ^1.1.0
  http: ^0.13.4
  intl: ^0.17.0
  json_annotation: ^4.4.0
  json_serializable: ^6.1.4
  shared_preferences: ^2.0.12
  g_recaptcha_v3: ^0.0.4

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^2.1.5
  freezed: ^1.0.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:
    - assets/images/
    - assets/image.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: Helvetica Neue
      fonts:
        - asset: assets/fonts/HelveticaNeue.ttf
        - asset: assets/fonts/HelveticaNeueBold.ttf
          weight: 700
    - family: Helvetica Neue Condensed
      fonts:
        - asset: assets/fonts/HelveticaNeueCond.ttf
        - asset: assets/fonts/HelveticaNeueCondBold.ttf
          weight: 700
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
jaredbaszler commented 2 years ago

Was able to reproduce this bug today in a new project using flutter create and the following code.

I also changed the target to desktop as well as web and I got the same error at the same location on both targets.

import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return FlutterLogin(
      title: 'Bug Example',
      theme: LoginTheme(
        primaryColor: const Color.fromRGBO(170, 30, 46, 1),
        accentColor: const Color.fromRGBO(243, 188, 71, 1),
        titleStyle: const TextStyle(
          fontFamily: 'Helvetica Neue Condensed',
          fontSize: 32,
        ),
      ),
      userValidator: (emailAddress) {
        return null;
      },
      passwordValidator: (password) {
        return null;
      },
      onLogin: (loginData) async {
        print('onLogin firing');
        return null;
      },
      onRecoverPassword: (name) => null,
      onSubmitAnimationCompleted: (loginData) {
        print('onSubmitAnimationCompleted firing');
        // Navigator.of(context).pushReplacement(MaterialPageRoute(
        //   builder: (context) => PCShipments(),
        // ));
      },
    );
  }
}

and my pubspec.yaml is:


name: pc_portal_frontend
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.15.1 <3.0.0"

dependencies:
  cupertino_icons: ^1.0.2
  flutter:
    sdk: flutter
  flutter_login: ^3.1.0

dev_dependencies:

  flutter_lints: ^1.0.0
  flutter_test:
    sdk: flutter

flutter:

  uses-material-design: true