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/屏幕/profile_screen. dart:36
:错误:参数类型“字符串”无法分配给参数类型“BuildContext”。lib/屏幕/profile_screen. dart:37
这是错误,我得到getData()async{try{var snap=await FirebaseFirestore.实例.集合('用户').文档(widget. uid).get();userData=snap.data()!;setState(() {}); } catch(e){showSnackBar(context,e.toString(), ); } }
你会尝试这个:
catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Save failed: ${e.toString()}')
)
);
}