Я создаю страницу приложения для фрилансеров, где профили фрилансеров будут отображаться на основе данных firebase, а под их профилем будет отображаться кнопка для перехода к их профилю. Эта функция (называемая showProfile
), которую я создал, возвращает черный экран при нажатии на кнопку. showProfile
отлично работает на всех остальных страницах, кроме этой. Может быть, это 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 СТРАНИЦЫ ПРОФИЛЯ, КОТОРЫЙ РАБОТАЕТ ОТЛИЧНО НА ДРУГИХ СТРАНИЦАХ.
посетите эту ссылку pastebin, так как код слишком длинный