[英]How to move to Specific user profile screen from a list in Flutter
I have a list of User which the list become from a model class我有一个用户列表,该列表来自 model class
final Consultant giovanni = Consultant(
id: 6,
consultantFirstName: 'Giovanni',
consultantLastName: 'Racchi',
consultantNickName: 'Ragoni Dreams',
consultantCategory: 'Amore',
consultantDescription: 'Ciao a tutti sono Giovanni',
consultantImageProfile: 'assets/images/giovanni.jpg',
consultantLikes: '4896',
consultantReviews: '76345',
consultantPrice: '4.55',
consultantExperience: '16',);
List<Consultant> consultant = [
marco,
carmela,
sabrina,
saverio,
pamela,
giovanni
];
into my list I have Gesture Detector which should move to the right profile when clicking on the right card profile where ConsultantProfile
screen is called在我的列表中,我有手势检测器,当单击调用ConsultantProfile
配置文件屏幕的右卡配置文件时,它应该移动到正确的配置文件
ListView.builder(
padding: EdgeInsets.all(5),
itemCount: consultant.length,
itemBuilder: (BuildContext context, int index) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ConsultantProfile(
),
),
),
child: Card(
elevation: 15,
child: Column(
children: [
Row(
obviously at the moment when clicking on a item of the list it moves to the first User Profile, but how to move to the right profile User when a specific Card User is Clicked?显然,在单击列表中的某个项目时,它会移动到第一个用户配置文件,但是当单击特定卡用户时如何移动到正确的配置文件用户?
make your ConsultantProfile
to take in an argument of Consultant
as shown below使您的ConsultantProfile
接受Consultant
的参数,如下所示
class ConsultantProfile extends StatefulWidget {
const ConsultantProfile({Key key, this.cosnsultant}) : super(key: key);
@override
_ConsultantProfileState createState() => _ConsultantProfileState();
final Cosnsultant cosnsultant;
}
class _ConsultantProfileState extends State<ConsultantProfile> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: Text(widget.cosnsultant. consultantFirstName),
),
),
);
}
}
//using stateless widget //使用无状态小部件
class ConsultantProfile extends StatelessWidget {
final Cosnsultant cosnsultant;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
child: Text(this.cosnsultant. consultantFirstName),
),
),
);
}
}
and then during navigation do parse your argument然后在导航期间解析你的论点
GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ConsultantProfile(
consultant:consultant[index],
),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.