[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method DocumentReference#setData on channel plugins.flutter.io/cloud_firestore)
Future<void> _createJob(BuildContext context) async{
final database = Provider.of<Database>(context);
await database.createJob(Job(name: 'Bloging', ratePerHour: 10));
}
import 'package:flutter/foundation.dart';
class Job{
Job({@required this.name, @required this.ratePerHour});
final String name;
final int ratePerHour;
Map<String, dynamic> toMap() {
return{
'name': name,
'ratePerHour': ratePerHour,
};
}
}
create: (_) => FirestoreDatabase(uid: user.uid),
child: JobsPage());
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:time_tracker/app/models/jobs.dart';
import 'dart:async';
import 'package:time_tracker/servises/api_path.dart';
abstract class Database {
Future<void> createJob (Job job);
}
class FirestoreDatabase implements Database {
FirestoreDatabase({@required this.uid}) : assert(uid != null);
final String uid;
Future<void> createJob (Job job) async {
final path = APIPAth.job(uid, 'job_abc');
final documentReference = Firestore.instance.document(path);
await documentReference.setData(job.toMap());
}
}
static String job (String uid, String jobId) => '/users/$uid/jobs/$jobId';
}