': Error: The argument type 'BuildContext Function()' can't be assigned to the parameter type 'String'
import 'dart:ui';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:mingle_flutter/utils/colors.dart';
import 'package:mingle_flutter/utils/utils.dart';
import 'package:mingle_flutter/widgets/follow_button.dart';
class ProfileScreen extends StatefulWidget {
final String uid;
const ProfileScreen({Key? key, required this.uid}) : super(key: key);
@override
State<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
var userData = {};
@override
void initState() {
super.initState();
getData();
}
getData() async {
try {
var snap = await FirebaseFirestore.instance
.collection('users')
.doc(widget.uid)
.get();
userData = snap.data()!;
setState(() {});
} catch (e) {
showSnackBar(
context,
e.toString(),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: mobileBackgroundColor,
title: Text(
userData['username'],
),
centerTitle: false,
),
body: ListView(
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Row(
children: [
CircleAvatar(
backgroundColor: Colors.grey,
backgroundImage: NetworkImage(
'https://cdn.pixabay.com/photo/2022/04/15/06/32/river-7133713__340.jpg',
),
radius: 40,
),
Expanded(
flex: 1,
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildStatColumn(20, "Posts"),
buildStatColumn(100, "Followers"),
buildStatColumn(5, "Following"),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FollowButton(
text: 'Edit Profile',
backgroundColor: mobileBackgroundColor,
textColor: primaryColor,
borderColor: Colors.grey,
function: () {},
),
],
),
],
),
),
],
),
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(
top: 15,
),
child: Text(
'username',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(
top: 1,
),
child: Text(
'Some description',
),
),
],
),
),
const Divider(),
],
),
);
}
Column buildStatColumn(int num, String label) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
num.toString(),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Container(
margin: const EdgeInsets.only(top: 4),
child: Text(
label,
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.w400, color: Colors.grey),
),
),
],
);
}
}
: Error: The argument type 'BuildContext Function()' can't be assigned to the parameter type 'String'. lib/screens/profile_screen.dart:36
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart'). package:flutter/…/widgets/framework.dart:1 context, ^
: Error: The argument type 'String' can't be assigned to the parameter type 'BuildContext'. lib/screens/profile_screen.dart:37
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart'). package:flutter/…/widgets/framework.dart:1 e.toString(), ^
This is the error I am getting getData() async { try { var snap = await FirebaseFirestore.instance .collection('users') .doc(widget.uid) .get(); userData = snap.data()!; setState(() {}); } catch (e) { showSnackBar( context, e.toString(), ); } }
Solution 1:[1]
you will be try this :
catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Save failed: ${e.toString()}')
)
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Emtn |
