2 years ago
#28307
DARK WORLD
'String' is not a sub type of type map<String, dynamic> flutter error
//Hello, I am trying to pass Map as an argument to the new screen but it ends in error with a red screen. here is my code first the class where the Map is defined, I am using firebase for a database with this app. I am trying to make get job app so the employer post the job(i use textformfield) but when I try to received data as a map it show error
class FloatSearchBar extends StatefulWidget {
const FloatSearchBar({Key? key}) : super(key: key);
@override
FloatSearchBarState createState() => FloatSearchBarState();
}
class FloatSearchBarState extends State<FloatSearchBar> with WidgetsBindingObserver {
Map<String, dynamic>? userMap;
late FloatingSearchBarController controller;
static const historyLength = 4;
@override
void initState() {
super.initState();
controller = FloatingSearchBarController();
filteredSearchHistory = filterSearchTerms(filter: null);
}
isLoading = true;
});
FirebaseFirestore _firestore = FirebaseFirestore.instance;
await _firestore
.collection("PostJob")
.where("jobType", isEqualTo: selectedTerm.toLowerCase())
.get()
.then((value) {
setState(() {
userMap = value.docs[0].data();
isLoading = false;
});
print(userMap);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => searchresultPage(
recevieduserMap: userMap!['jobType'], key: UniqueKey())));
});
}
...
*and now the class which is getting pushed:-
...class searchresultPage extends StatelessWidget {
FloatSearchBar yes = new FloatSearchBar();
Map<String, dynamic> recevieduserMap ;
searchresultPage({required this.recevieduserMap,Key? key,}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
Positioned.fill(
top: 70,
child: Align(
alignment: Alignment.center,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Card(
elevation: 15,
child: Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(padding: EdgeInsets.all(2)),
Text('Job Type:- ' + recevieduserMap["jobType"],style: GoogleFonts.breeSerif(
textStyle: TextStyle(
fontSize: 20,wordSpacing: 1),),),
Text('Job Descreption:- '+recevieduserMap["jobDescrebtion"],style: GoogleFonts.breeSerif(
textStyle: TextStyle(
fontSize: 20,wordSpacing: 1),),),
Text('Company Location:- '+recevieduserMap["companyLocation"],style: GoogleFonts.breeSerif(
textStyle: TextStyle(
fontSize: 20,wordSpacing: 1),),),
Text('Company Name:- '+recevieduserMap["companyName"],style: GoogleFonts.breeSerif(
textStyle: TextStyle(
fontSize: 20,wordSpacing: 1),),),
Text('\$${recevieduserMap["payrate"]}'.toString(),style: GoogleFonts.breeSerif(
textStyle: TextStyle(
fontSize: 20,wordSpacing: 1),)),
],
),
),
),
],
),
),
),
],
),
),
),
],
),
),
);
}
}
...
flutter
hybrid-mobile-app
dart-null-safety
0 Answers
Your Answer