본문 바로가기

VoidCallback3

Flutter VoidCallback에 매개변수가 있는 함수를 전달하세요., Pass a function with parameters to a VoidCallback 질문 Function에 매개 변수를 전달하여 VoidCallback을 전달하는 것이 가능한가요? 예를 들어 다음과 같은 것이 있을까요: class MyClass { void doSomething(int i){ } MyOtherClass myOtherClass = new MyOtherClass(doSomething); } class MyOtherClass { final VoidCallback callback(int); MyOtherClass(this.callback); callback(5); } 답변 VoidCallback의 선언은 다음과 같습니다. typedef void VoidCallback(); 이는 인자가 없고 유용한 값을 반환하지 않는 함수의 타입입니다. 이것이 원하는 것은 아닌 것 같습니다. 프.. 2023. 6. 14.
Flutter 비동기 간격을 건너서 BuildContext를 사용하지 마십시오., Do not use BuildContexts across async gaps 질문 내 프로젝트에서 새로운 린트 이슈를 발견했습니다. 간단히 말해서: 내 커스텀 클래스에서 BuildContext를 사용해야 합니다. aysnc 메서드와 함께 사용할 때 flutter 린트 도구가 행복하지 않습니다. 예시: MyCustomClass{ final buildContext context; const MyCustomClass({required this.context}); myAsyncMethod() async { await someFuture(); # if (!mounted) return; _MyWidgetState(); } class _MyWidgetState extends State { @override Widget build(BuildContext context) { return Icon.. 2023. 5. 31.
Flutter 널 안전성 이후에는 'Function' 인수 유형이 'void Function()?' 매개 변수 유형에 할당될 수 없습니다., The argument type 'Function' can't be assigned to the parameter type 'void Function()?' after null safety 질문 저는 서랍에 다른 항목들을 만들고 싶어서, DrawerItems를 위한 별도의 파일을 만들고 생성자를 통해 데이터를 메인 파일로 전달하려고 합니다. 그러나 onPressed 함수에서 다음과 같은 오류가 발생합니다: "The argument type 'Function' can't be assigned to the parameter type 'void Function()'" class DrawerItem extends StatelessWidget { final String text; final Function onPressed; const DrawerItem({Key key, this.text, this.onPressed}) : super(key: key); @override Widget build(B.. 2023. 5. 26.