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
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
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: