我正在创建一个自由职业者应用程序页面,在该页面中,将基于Firebase数据显示自由职业者个人资料,并显示其个人资料下方的按钮以导航至其个人资料。我创建的此函数(称为showProfile
)在单击按钮时会返回黑屏。 showProfile
可以在除此以外的所有其他页面上完美运行。 c是StreamBuilder
吗?
class Designer extends StatefulWidget {
@override
_DesignerState createState() => _DesignerState(
]
);
}
class _DesignerState extends State<Designer> {
int likeCount;
Map likes;
bool isLiked;
bool showHeart = false;
int followerCount = 0;
Icon cusIcon = Icon(Icons.search);
Widget cusSearch = Text( 'Designer',
style: TextStyle(
fontFamily :"MajorMonoDisplay",
fontSize: 35.0 ,
color: Colors.white),);
@override
Widget build(BuildContext context) {
return Scaffold( appBar: AppBar(backgroundColor: kPrimaryColor,
title: cusSearch,
iconTheme: new IconThemeData(color: kSecondaryColor),
actions: <Widget>[
IconButton( onPressed: () {
setState(() {
if (this.cusIcon.icon == Icons.search){
this.cusIcon = Icon(Icons.clear);
this.cusSearch = TextField(
textInputAction: TextInputAction.go,
decoration: InputDecoration(
border:InputBorder.none,
hintText: "Search",
),
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
);
}
else{
this.cusIcon = Icon(Icons.search);
this.cusSearch = Text( 'Designer',
style: TextStyle(
fontFamily :"MajorMonoDisplay",
fontSize: 35.0 ,
color: Colors.white),);
}
});
// do something
},
icon: cusIcon,
),
]
),
backgroundColor: kSecondaryColor,
body: StreamBuilder(
stream: Firestore.instance.collection("users").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return circularProgress();
} else {
return new ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot doc = snapshot.data.documents[index];
return new dItem(
id: doc['id'],
username :doc['username'],
email :doc['email'],
photoUrl: doc['photoUrl'],
displayName :doc['displayName'],
bio :doc['bio'],
);
}
);
}
}
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.black38,
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.add_circle_outline),
),
);
}
}
class dItem extends StatelessWidget {
final String id;
final String username;
final String email;
final String photoUrl;
final String displayName;
final String bio;
dItem({ this.id,
this.username,
this.email,
this.photoUrl,
this.displayName,
this.bio,
});
showProfile(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Profile(
profileId: id,
)));
}
@override
Widget build(BuildContext context) {
return Container(
child:Column(
children: [
ListTile(
leading: Container(
height: 40,
width: 40,
child: CircleAvatar(
backgroundImage: CachedNetworkImageProvider(photoUrl),
),
),
title:Container(
child: Text(displayName),
),
subtitle: Container(
child: Text(username),
),
),
SizedBox(height: 10.0,),
FloatingActionButton(
onPressed: () =>showProfile( context))
],
),
);
}
}
这是个人资料页DART文件,可以在其他页面上完美地工作。