:错误:参数类型' buildContext function()'可以将参数类型分配给字符串'
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),
),
),
],
);
}
}
:错误:参数类型'buildContext function()'不能分配给参数类型'string'。 lib/screens/profile_screen.dart:36'buildContext
- '来自“软件包:flutter/src/widgets/framework.dart'('../ ../ ../ ../ downloads/flutter/packages/packages/flutter/lib/src/src/widgets/frameworks/frameworks/framework 。镖')。 软件包:flutter/…/widgets/framework.dart:1 语境, ^
:错误:参数类型'字符串'无法分配给参数类型'buildContext'。 lib/screens/profile_screen.dart:37'buildContext
- '来自'package:flutter/src/widgets/framework.dart'('../ ../ ../ ../ downloads/flutter/packages/flutter/flutter/lib/src/src/src/widgets/widgets/frameworks/framework 。镖')。 软件包:flutter/…/widgets/framework.dart:1 e.tostring(), ^
这是我遇到的错误 getData()async {try {var snap =等待firebasefirestore.instance .collection('users'users').doc(widget.uid).get(); userData = snap.data()!; setState((){}); } catch(e){shownackbar(context,e.tostring(),); }}}
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(), ); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将尝试一下:
you will be try this :