Flutter - Pass The Function into the parameter of another function
Автор: True Coders
Загружено: 2022-10-13
Просмотров: 5486
Dart function passed to other functions as a parameter.
Solve
The argument type 'Function' can't be assigned to the parameter type 'void Function()?'.
Code
--------
Class
class ReusableContainerWidget extends StatelessWidget {
const ReusableContainerWidget({
Key? key,
required this.btnClick,
}) : super(key: key);
final Function() btnClick;
@override
Widget build(BuildContext context) {
return Container(
child: ElevatedButton(
child: Text('Click'),
onPressed: btnClick,
),
);
}
}
Function call
----------------------
ReusableContainerWidget(btnClick: (){
print('Second Button');
},),
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: