is there a way to path this "model" from commentItem Widget to a Navigator that transmit me to another screen ?
like Navigator.push or Navigator.pushNamed ?
it will help me to display posts or comments in different screens like home screen it will display posts
as well as my profile screen it will display only my posts so i need to know how to path arguments to different screens by Navigator
how to perform this with code ?
Widget commentItem(CommentModel model, context,) => Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 22,
backgroundImage: NetworkImage('${model.image}'),
),
SizedBox(
width: 15,
),
Expanded(
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: SocialCubit.get(context).iconChangeTheme? Colors.white70 : Colors.grey[350],
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
'${model.name}',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: SocialCubit.get(context).iconChangeTheme? Colors.black : Colors.black
),
),
SizedBox(
width: 7,
),
Text(
'${model.dateTime}',
style: TextStyle(
fontSize: 11,
color: SocialCubit.get(context).iconChangeTheme? Colors.black : Colors.black
),
),
],
),
if(model.text != '')
SizedBox(
height: 5,
),
Text('${model.text}'
,style: TextStyle(
color: SocialCubit.get(context).iconChangeTheme? Colors.black : Colors.black
),),
],
),
),
),
if (model.commentImage != '')
Padding(
padding: const EdgeInsetsDirectional.only(top: 5),
child: Container(
height: 170,
//width: double.infinity,
alignment: Alignment.topLeft,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image(image: NetworkImage('${model.commentImage}'),
//fit: BoxFit.fill,
alignment: Alignment.topLeft),
),
),
),
],
),
),
],
),
],
);
ListView.separated(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => commentItem(SocialCubit.get(context).comments[index], context,),
separatorBuilder: (context, index) => SizedBox(height: 20),
itemCount: SocialCubit.get(context).comments.length),
2
Answers
You can use the Navigator push as following:
Your class will look like following:
if using
Stateless
widget, you can access the passed data throughNavigator
directly likepostCode
,week
orpostName
etc. If usingStateful
, you need to usewidget.postCode
,widget.week
orwidget.postName
notation.using Getx Package
Get.to(ScreenName());
https://pub.dev/packages/get