'Can't define the 'const' constructor because the field 'currentUser' is initialized with a non-constant value
- Can't define the 'const' constructor because the field 'currentUser' is initialized with a non-constant value.
- Can't define a const constructor for a class with non-final fields.
- The argument type 'Stream<QuerySnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Widget Function(BuildContext, AsyncSnapshot<QuerySnapshot<Object?>>)'.
- The argument for the named parameter 'builder' was already specified.
- The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type.
how to solve this error. appriciate your help on this.
people.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
class People extends StatelessWidget {
const People({Key? key}) : super(key: key);
var currentUser = FirebaseAuth.instance.currentUser!.uid;
void callChatScreen(String name, String uid){
}
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
builder: FirebaseFirestore.instance
.collection("users")
.where('uid',isNotEqualTo: currentUser)
.snapshots(),
builder:(BuildContext,AsyncSnapshot<QuerySnapshot>snapshot){
if(snapshot.hasError){
return Center(
child: Text("Something went wrong"),
);
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text("Loading"),
);
}
if (snapshot.hasData) {
return CustomScrollView(
slivers: [
CupertinoSliverNavigationBar(
largeTitle: Text("People"),
),
SliverList(
delegate: SliverChildListDelegate(
snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic>? data = document.data() as Map<String, dynamic>?;
return CupertinoListTile(
onTap:()=> callChatScreen(data['name'],data['uid'])
title: Text(data!['name']),
subtitle: Text(data['status']),
);
}).toList()))
],
);
}
//return Container();
});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
