I'm learning flutter from the older version with the new one. so, I have many times problem with null safety.
I have code in database.dart
file like this :
import 'package:cloud_firestore/cloud_firestore.dart';
class DatabaseService {
final String uid;
DatabaseService({required this.uid});
}
it works and no error appeared when I add "required", but I can't use DatabaseService()
parameter in home.dart
file :
class Home extends StatelessWidget {
Home({Key? key}) : super(key: key);
final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
return StreamProvider<QuerySnapshot?>.value(
initialData: null,
value: DatabaseService().brews,
child: Scaffold(),
}
}
the error in home.dart
is
The named parameter 'uid' is required, but there's no corresponding argument.
Try adding the required argument.
and, if I don't add required in DatabaseService({this.uid})
then the error will appear in database.dart
The parameter 'uid' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
then how I can use DatabaseService()
in other file ?