skip to Main Content

I’m still a noob in Flutter and recently I just downloaded the latest Flutter version on my machine but every time I try to run my project I get this error:

C:UserskhomoOneDriveDocumentsGitHubluvart-Project.dart_toolflutter_build99035e6341f80e4f3744d732501fdc7dnative_assets.yaml --verbosity=error package:luvart/main.dart
[+11601 ms] [+11647 ms] ../../../../AppData/Local/Pub/Cache/hosted/pub.dev/smithy-0.5.2/lib/src/http/http_operation.dart:271:16: Error: A value of type 'Object?' can't be assigned to a variable of type 'Output?'.
[  +36 ms] [   +4 ms]  - 'Object' is from 'dart:core'.
[        ] [        ]       output = switch (payload) {
[        ] [        ]                ^ 

I’m not quite sure where the error is in my main.dart file or how to fix it or even if the error is actually there. Here’s how my main.dart file looks:

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_datastore/amplify_datastore.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_storage_s3/amplify_storage_s3.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:luvart/amplifyconfiguration.dart';
import 'package:luvart/entry_point.dart';

import 'models/ModelProvider.dart';

void main() {
  runApp(
    const ProviderScope(
      child: MyApp(),
    ),
  );
}

class MyApp extends ConsumerStatefulWidget {
  const MyApp({super.key});

  @override
  ConsumerState<MyApp> createState() => _MyAppState();
}

class _MyAppState extends ConsumerState<MyApp> {
  bool isAmplifyConfigured = false;

  @override
  void initState() {
    super.initState();
    _configAmplify();
  }

  Future<void> _configAmplify() async {
    try {
      await Amplify.addPlugins(
        [
          AmplifyAPI(),
          AmplifyAuthCognito(),
          AmplifyDataStore(modelProvider: ModelProvider.instance),
          AmplifyStorageS3(),
        ],
      );

      await Amplify.configure(amplifyconfig);

      setState(() {
        isAmplifyConfigured = true;
      });
    } on Exception catch (e) {
      if (kDebugMode) {
        print('$e');
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'luvart',
      themeMode: ThemeMode.light,
      theme: ThemeData(
        useMaterial3: true,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        primaryColor: Colors.black,
        scaffoldBackgroundColor: Colors.white,
        appBarTheme: const AppBarTheme(
          backgroundColor: Colors.white,
          elevation: 0.0,
        ),
      ),
      home: isAmplifyConfigured == false
          ? const Scaffold(
              body: Center(
                child: CircularProgressIndicator(),
              ),
            )
          : const EntryPoint(),
    );
  }
}

Please help and thanks in advance

2

Answers


  1. the version of smithy library you are using is outdated. Please use smithy version -> 0.6.1 this has the fix for the error you are getting. Ref:
    https://github.com/aws-amplify/amplify-flutter/commit/6ab1a671273fd8573875faad1b2f3ae8a616227a

    Login or Signup to reply.
  2. I got the same error after updating the flutter to the latest version.
    The solution was inspired by: @Saiful.

    Check your outdated packages with flutter pub outdated

    After that, you can upgrade your older packages at the pubspec.yaml.

    Update all related Amplify resources:

    > amplify_analytics_pinpoint 1.6.1 (was 1.4.1)
    > amplify_analytics_pinpoint_dart 0.3.4 (was 0.3.1)
    > amplify_api 1.6.1 (was 1.4.0)
    > amplify_api_dart 0.3.3 (was 0.3.1+1)
    > amplify_auth_cognito 1.6.0 (was 1.4.2)
    > amplify_auth_cognito_dart 0.10.6 (was 0.10.4) (0.10.7 available)
    > amplify_authenticator 1.5.1 (was 1.4.2)
    > amplify_core 1.6.1 (was 1.4.1)
    > amplify_db_common 0.3.3 (was 0.3.1+1)
    > amplify_db_common_dart 0.3.3 (was 0.3.1)
    > amplify_flutter 1.6.0 (was 1.4.1)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search