Cannot execute Firebase Query within Isolate - firebase

I'm developping an app using Flutter. And I want to execute some Firebase queries using Isolate.
But each time I run the app I get this error and nothing is displayed.
Here my code
class HomePage extends StatefulWidget {
HomePage({Key key, this.title}) : super(key: key);
final String title;
#override
HomePageState createState() => HomePageState();
}
class HomePageState extends State<HomePage>{
Isolate _isolate;
ReceivePort _receivePort;
String _data;
#override
Widget build(BuildContext context){
return WillPopScope(
child: Scaffold(){
child : Center(child:Text('${_data}'))
});
}
//To start
void _start() async {
_receivePort = ReceivePort();
_isolate = await Isolate.spawn(getData, _receivePort.sendPort);
_receivePort.listen(_displayData, onDone: () {
print("done!");
});
}
//Display data;
void _displayData(dynamic data) {
setState(() {
_data = data;
});
}
static void getData(SendPort sendPort) async{
var fire = Firestore.instance;
fire.settings(persistenceEnabled: true); //I get an error here
fire.document('MODEL/${id}')
.snapshots()
.listen((d) {//I get an error here
sendPort.send(d);
}
}
}
//I call the method _start in the initState
#override
void initState() {
_start();
super.initState();
}
Here is the error that I get
E/flutter (14817): [ERROR:flutter/runtime/dart_isolate.cc(808)] Unhandled exception:
E/flutter (14817): error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
E/flutter (14817): #0 Window.sendPlatformMessage (dart:ui/window.dart:1133:9)
E/flutter (14817): #1 _DefaultBinaryMessenger._sendPlatformMessage (package:flutter/src/services/binary_messenger.dart:85:15)
E/flutter (14817): #2 _DefaultBinaryMessenger.send (package:flutter/src/services/binary_messenger.dart:129:12)
E/flutter (14817): #3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:309:51)
E/flutter (14817):
E/flutter (14817): #4 Query.snapshots. (package:cloud_firestore/src/query.dart:61:37)
E/flutter (14817): #5 _runGuarded (dart:async/stream_controller.dart:805:24)
E/flutter (14817): #6 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:213:7)
E/flutter (14817): #7 _ControllerStream._createSubscription (dart:async/stream_controller.dart:818:19)
E/flutter (14817):
E/flutter (14817): #4 Firestore.settings (package:cloud_firestore/src/firestore.dart:154:19)
E/flutter (14817):
E/flutter (14817): #5 HomePageState.getData (package:flutter_app/HelpFile/HomePage.dart:207:10)
E/flutter (14817): #8 _StreamImpl.listen (dart:async/stream_impl.dart:472:9)
E/flutter (14817): #9 HomePageState.getData (package:flutter_app/HomePage.dart:201:10)
E/flutter (14817):
E/flutter (14817): #10 _startIsolate. (dart:isolate-patch/isolate_patch.dart:308:17)
E/flutter (14817): #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

Check this link https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp
Any FirebaseApp initialization must occur only in the main process of the app. Use of Firebase in processes other than the main process is not supported and will likely cause problems related to resource contention.

Related

Firebase.initializeApp() gives error: Null check operator used on a null value

running this
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: ThePage(),
);
}
}
class ThePage extends StatelessWidget {
const ThePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
);
}
}
is giving Null check operator used on a null value and pointing out the line Firebase.initializeApp().
I have tried flutter clean too.
and the error in the stack trace
E/flutter (31894): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
E/flutter (31894): #0 MethodChannel.binaryMessenger
package:flutter/…/services/platform_channel.dart:142
E/flutter (31894): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:148
E/flutter (31894): #2 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:331
E/flutter (31894): #3 MethodChannel.invokeListMethod
package:flutter/…/services/platform_channel.dart:344
E/flutter (31894): #4 MethodChannelFirebase._initializeCore
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:30
E/flutter (31894): #5 MethodChannelFirebase.initializeApp
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:77
E/flutter (31894): #6 Firebase.initializeApp
package:firebase_core/src/firebase.dart:41
E/flutter (31894): #7 main
package:firebasetests/main.dart:5
E/flutter (31894): #8 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
E/flutter (31894): #9 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (31894): #10 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (31894): #11 _runZoned (dart:async/zone.dart:1789:10)
E/flutter (31894): #12 runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter (31894): #13 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
E/flutter (31894): #14 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (31894): #15 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
This is the stack trace for the error, after removing Firebase.initializeApp() in the main it runs fine.
You should add the WidgetsFlutterBinding.ensureInitialized(); inside the main function:
void main() async {
WidgetsFlutterBinding.ensureInitialized(); // Add this
await Firebase.initializeApp();
runApp(MyApp());
}
For Firebase initialization, access to the native code is needed using Flutter Platform Channels. For this, you need to ensure that Flutter engine binding is initialized.
Use line of code which #mkobuolys mentioned.
I had same problem in Visual Studio Code but it didn't shows me any detailed information about error but Android Studio did.
Here is the most important information from the exception message if anyone is interested:
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. 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.
add this line in android/app/build.gradle, this is worked for me
apply plugin: 'com.google.gms.google-services'

Flutter firebase function error : Response is not valid JSON object

Hello I tried to use firebase function by using Cloud_Functions Pkg but I got error in flutter consel , I tried to pass parameters in function which is UID of user .
Consel Error :
E/flutter (17871): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [firebase_functions/internal] Response is not valid JSON object.
E/flutter (17871): #0 catchPlatformException
package:cloud_functions_platform_interface/…/utils/exception.dart:21
E/flutter (17871): #1 _rootRunBinary (dart:async/zone.dart:1378:47)
E/flutter (17871): #2 _CustomZone.runBinary (dart:async/zone.dart:1272:19)
E/flutter (17871): #3 _FutureListener.handleError (dart:async/future_impl.dart:166:20)
E/flutter (17871): #4 Future._propagateToListeners.handleError (dart:async/future_impl.dart:716:47)
E/flutter (17871): #5 Future._propagateToListeners (dart:async/future_impl.dart:737:24)
E/flutter (17871): #6 Future._completeError (dart:async/future_impl.dart:547:5)
E/flutter (17871): #7 _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13)
E/flutter (17871): #8 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart)
package:flutter/…/services/platform_channel.dart:1
E/flutter (17871): <asynchronous suspension>
Firebse Function :
exports.helloWorld = functions.https.onCall((data, context) => {
return data.data()['uid'];
});
Flutter run function from Firebase :
IconButton(
icon: Icon(Icons.add),
onPressed: () async {
HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('listFruit');
final results = await callable.call(<String, dynamic>{
'uid': '123',
});
print(results
.data.toString()); // ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes"]
});
My goal :
pass parameters to firebase function .
I had the same error and it was due to the fact that the region was not provided, which seems to be required if the function is not deployed in us-central1. Following their documentation, you can perform the call like this:
FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('listFruit');
Instead of
exports.helloWorld = functions.https.onCall((data, context) => {
return data.data()['uid'];
});
you should do
exports.helloWorld = functions.https.onCall((data, context) => {
return data['uid']; // Or data.uid
});
Few more details in the Callable Cloud Functions doc.
In addition, note that your Cloud Function is named helloWorld but you call it with FirebaseFunctions.instance.httpsCallable('listFruit');. So you should adapt one or the other, e.g. FirebaseFunctions.instance.httpsCallable('helloWorld');

Importing Sqlite Database from a File in Flutter

I have a Sqlite database file that is always in the same spot on the device, in Documents named backup.db. What I want is to import that database to replace existing Sqlite database, but I am getting some strange errors. Anyways, here is the code:
class DbHelper {
static const currentDatabaseVersion = 1;
Future<void> init() async {
Database db;
final dbPath = await ExtStorage.getExternalStoragePublicDirectory(
ExtStorage.DIRECTORY_DOCUMENTS);
final newPath = join(dbPath, '/backup.db');
String localDatabasePath = newPath;
//Internal database path
var databasesPath = await getDatabasesPath();
var path = join(databasesPath, "foodDB.db");
db = await openDatabase(path);
if (await db.getVersion() < currentDatabaseVersion) {
db.close();
await deleteDatabase(path);
await _checkParentDirectoryExists(path);
ByteData data = await _getByteDataFromLocalDatabase(localDatabasePath);
List<int> bytes = _databaseByteDataToList(data);
await _writeBytesToInternalDatabase(path, bytes);
db = await openDatabase(path);
db.setVersion(currentDatabaseVersion);
}
}
static Future<void> _checkParentDirectoryExists(var path) async {
try {
await Directory(dirname(path)).create(recursive: true);
} catch (e) {
print(e);
}
}
static Future<ByteData> _getByteDataFromLocalDatabase(
String localDatabasePath) async {
return await rootBundle.load(join(localDatabasePath));
}
static List<int> _databaseByteDataToList(ByteData data) {
return data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
}
static Future<void> _writeBytesToInternalDatabase(
var path, List<int> bytes) async {
await File(path).writeAsBytes(bytes, flush: true);
}
}
As far as I got, it gets the 'documents' directory, merges the path with backup.db file that already exists in Documents, then it should just import it if it exists. Let me know if there is anything I am doing wrong. I am using the ext_storage library to locate the documents folder and sqlite of course to be able to import the database.
And in another screen I call this function like this:
DbHelper dbHelper = new DbHelper();
onTap: () => dbHelper.init(),
Here's the stacktrace:
ter (25910): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Unable to load asset: /backup.db
E/flutter (25910): #0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:225
E/flutter (25910): <asynchronous suspension>
E/flutter (25910): #1 DbHelper._getByteDataFromLocalDatabase
package:CWCFlutter/db/import_database.dart:72
E/flutter (25910): #2 DbHelper.init
package:CWCFlutter/db/import_database.dart:53
E/flutter (25910): <asynchronous suspension>
E/flutter (25910): #3 _FoodListState.build.<anonymous closure>
package:CWCFlutter/food_list.dart:919
E/flutter (25910): #4 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter (25910): #5 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter (25910): #6 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter (25910): #7 BaseTapGestureRecognizer.acceptGesture
package:flutter/…/gestures/tap.dart:259
E/flutter (25910): #8 GestureArenaManager.sweep
package:flutter/…/gestures/arena.dart:157
E/flutter (25910): #9 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:362
E/flutter (25910): #10 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter (25910): #11 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter (25910): #12 GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:295
E/flutter (25910): #13 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:240
E/flutter (25910): #14 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:213
E/flutter (25910): #15 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (25910): #16 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (25910): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (25910): #18 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter (25910): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
When I tap on the button to import the database, it is completely unresponsive, not sure what the issue is.
Try the code below. It is similar to what you want but also with a versioning system. When you init the database, it will open the database in the phone directory and check the version of that. If it's outdated or doesn't exist it will delete the current one and create a new one (or just create a new one in the case that it doesn't exist).
static const currentDatabaseVersion = 1;
static Future<void> init() async {
Database db;
String localDatabasePath = 'your database path here';
//Internal database path
var databasesPath = await getDatabasesPath();
var path = join(databasesPath, "database.db");
db = await openDatabase(path);
if (await db.getVersion() < currentDatabaseVersion) {
db.close();
await deleteDatabase(path);
await _checkParentDirectoryExists(path);
ByteData data = await _getByteDataFromLocalDatabase(localDatabasePath);
List<int> bytes = _databaseByteDataToList(data);
await _writeBytesToInternalDatabase(path, bytes);
db = await openDatabase(path);
db.setVersion(currentDatabaseVersion);
}
}
static Future<void> _checkParentDirectoryExists(var path) async {
try {
await Directory(dirname(path)).create(recursive: true);
} catch (e) {
print(e);
}
}
static Future<ByteData> _getByteDataFromLocalDatabase(
String localDatabasePath) async {
return await rootBundle.load(join(localDatabasePath));
}
static List<int> _databaseByteDataToList(ByteData data) {
return data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
}
static Future<void> _writeBytesToInternalDatabase(
var path, List<int> bytes) async {
await File(path).writeAsBytes(bytes, flush: true);
}

How to save multiple images to firebase storage and get image urls at once?

I'm trying to save multiple images from a list to firebasestorage and get back references of all these images and then saving it to cloud firestore !
This list is List<menu> menus = []; here.
Multiple objects including paths of images only from phone are being saved from UI in this list(menus) and then I'm uploading images using these paths to firestorage and getting back its references to save it in firestore:
onPressed: () async {
for (var i; i <= menus.length; i++) {
Reference ref = storage.ref().child(
"${this.widget.rr.name}'s ${menus[i].itemName} Price ${menus[i].itemPrice}" +
DateTime.now().toString());
if (menus[i].imageFile.toString() == '') {
//Some code
} else {
UploadTask uploadTask = ref.putFile(menus[i].imageFile);
uploadTask.then((res) async {
menus[i].imageUrl = await res.ref.getDownloadURL();
});
}
}
await addUser();
},
This is addUser() function:
Future<void> addUser() {
return users
.add({
'name': this.widget.rr.name,
'email': this.widget.rr.email,
'password': this.widget.rr.password,
'logoUrl': this.widget.rr.logo,
'categories': this.widget.rr.categories,
'menu': menus.map((i) => i.toMap()).toList(),
})
.then((value) => print("User Added"))
.catchError((error) => print("Failed to add user: $error"));
}
And this is Model class
class menu{
int id;
String itemName;
String itemPrice;
String itemDescription;
File imageFile;
String imageUrl;
menu(this.id,this.itemName,this.itemPrice,this.itemDescription,this.imageFile,{this.imageUrl});
Map<String, dynamic> toMap() {
return {
'id': this.id,
'itemName': this.itemName,
'itemPrice': this.itemPrice,
'itemDesc': this.itemDescription,
'imageUrl':this.imageUrl,
};
}
}
But when the button is pressed, following error is displayed...
E/flutter (12025): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '<=' was called on null.
E/flutter (12025): Receiver: null
E/flutter (12025): Tried calling: <=(2)
E/flutter (12025): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (12025): #1 _addMenuState.build.<anonymous closure> (package:ad_tello/UI/Restaurants/addMenu.dart:418:33)
E/flutter (12025): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (12025): #3 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter (12025): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (12025): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter (12025): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter (12025): #7 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:259:7)
E/flutter (12025): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
E/flutter (12025): #9 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:362:20)
E/flutter (12025): #10 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter (12025): #11 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter (12025): #12 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (12025): #13 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter (12025): #14 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter (12025): #15 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (12025): #16 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (12025): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (12025): #18 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter (12025): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter (12025):
Help please!
You have to initialize i:
for (var i = 0; i < menus.length; i++) {

type 'String' is not a subtype of type 'File'

So far in my app everything is working except that one error I keep getting:
type 'String' is not a subtype of type 'File'
I tried many ways to try and fix the Issue but nothing has yet been resolved.
I can understand where the issue is, but I'm unable to fix it with countless attempts.
The problem is that im passing an Image using ImagePicker gallery im passing that image data to firebase as image: image.toString() and it works fine. Firebase takes the path but as an error i get: _file != null since the image is indeed a File image I cant fetch the data from firebase and pass the string path as an argument. therefore getting this error type 'String' is not a subtype of type 'File'. I display the image on the app like the following Image.file(image) Since its the only way to display a File image and use the ImagePicker. Is there a solution for this? or is it a bad way of doing the idea im trying to achieve?
here is the code:
image picker:
String img;
static Future<String> fileToB64(File f) async {
List<int> imageBytes = f.readAsBytesSync();
return base64Encode(
imageBytes,
);
}
Future<void> _takePicture() async {
final imageFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
);
setState(() {
data.image = imageFile;
});
fileToB64(imageFile).then((d) {
setState(() {
img = d; //base64Decode(d);
});
});
}
the provider:
import: 'dart:io';
class AddCar {
// other data
File image;
AddCar({
this.// other data
this.image,
});
}
firebase data:
Future<void> fetchAndSetCars() async {
const url = 'https://mylink.firebaseio.com/cars.json';
try {
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
final List<AddCar> loadedCars = [];
extractedData.forEach((carId, carData) {
loadedCars.add(AddCar(
// other data
image: carData['image'],
));
});
_cars = loadedCars;
notifyListeners();
} catch (error) {
throw (error);
}
}
AddCar findById(String id) {
return _cars.firstWhere((carProd) => carProd.id == id);
}
void addCar(AddCar car) {
const url = 'https://mylink.firebaseio.com/cars.json';
http.post(
url,
body: json.encode({
// other data
'image': car.image.toString(),
}),
);
final newCar = AddCar(
// other data
image: car.image,
);
_cars.insert(0, newCar); // add car at the top of the list
notifyListeners();
}
how im displaying the fetch data from firebase:
#override
void initState() {
Future.delayed(Duration.zero).then((_) {
Provider.of<Cars>(context).fetchAndSetCars();
});
super.initState();
}
how im calling the data to be displayed in the app:
Container(
width: MediaQuery.of(context).size.width * 0.35,
height: MediaQuery.of(context).size.width * 0.35,
child: GestureDetector(
child: Image.file(
image,
fit: BoxFit.fill,
),
onTap: () {
Navigator.of(context).pushNamed(
MyCarDetails.routeName,
arguments: id,
);
},
),
),
What I get when I run the app:
Restarted application in 6,085ms.
E/flutter ( 3497): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'File'
E/flutter ( 3497): #0 Cars.fetchAndSetCars
package:flutter_app/providers/car_provider.dart:54
E/flutter ( 3497): <asynchronous suspension>
E/flutter ( 3497): #1 _CarAreaState.initState.<anonymous closure>
package:flutter_app/home_parts/cars_area.dart:28
E/flutter ( 3497): #2 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 3497): #3 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 3497): #4 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter ( 3497): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter ( 3497): #6 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter ( 3497): #7 Future._complete (dart:async/future_impl.dart:512:7)
E/flutter ( 3497): #9 _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 3497): #10 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 3497): #11 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 3497): #12 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter ( 3497): #13 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 3497): #14 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 3497): #15 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter ( 3497): #16 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter ( 3497): #17 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter ( 3497): #18 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter ( 3497): #19 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
It seems that instead of doing this:
image: carData['image']
You should do this:
image: File(carData['image'])
Because carData['image'] is a String, not a File, and AddCar expects a File.
sometimes it's because of using ! null safety you should run like flutter run --no-sound-null-safety

Resources