Hi I'm trying to use aligned_dialog package from flutter to show certain dialog for my button in my separated class but it show argument type error co-related to the builder. How can I fix this ?
error: The argument type 'BuildContext' can't be assigned to the parameter type 'Widget Function(BuildContext)'. (argument_type_not_assignable at [tiket_kerja] lib\widgets\reusable_role_container.dart:172)
Here's my code:
GestureDetector(
onTap: (){
showAlignedDialog(
context: context,
builder: context,
followerAnchor: Alignment.topLeft,
targetAnchor: Alignment.bottomRight,
barrierColor: Colors.transparent,
avoidOverflow: true,
);
},
child: Container(
width: 20,
height: 20,
child: SvgPicture.asset(
'assets/logo/Information.svg',
),
),
),
I tried to use this.context but it still show the error. Can someone please explain the problem please ? Is it related to the stateless widget and not stateful ?
CodePudding user response:
The issue is you have added context to the builder.. But Builder is expecting a widget
builder: context,
use some widget instead
builder: (context) {
return Container();
}
CodePudding user response:
instead of this:
GestureDetector(
onTap: (){
showAlignedDialog(
context: context,
builder: context,
followerAnchor: Alignment.topLeft,
targetAnchor: Alignment.bottomRight,
barrierColor: Colors.transparent,
avoidOverflow: true,
);
},
child: Container(
width: 20,
height: 20,
child: SvgPicture.asset(
'assets/logo/Information.svg',
),
),
),
try this:
GestureDetector(
onTap: (){
showAlignedDialog(
context: context,
builder: (BuildContext context) {
/// change this return widget to your
///widget that going to show in dialog
return Container(
width: 600,
height: 360,
child: SvgPicture.asset(
'assets/logo/Information.svg',
),
);
},
followerAnchor: Alignment.topLeft,
targetAnchor: Alignment.bottomRight,
barrierColor: Colors.transparent,
avoidOverflow: true,
);
},
child: Container(
width: 20,
height: 20,
child: SvgPicture.asset(
'assets/logo/Information.svg',
),
),
),
in build you should put something that you are going to show in that dialog.