티스토리 뷰

반응형

버튼을 클릭하면, 15초 후에 사라지는 dialog를 생성하고 싶었다. 

그래서 dialog의 initState()에 Timer.periodic 을 실행하도록 하고, 이 타이머에서 15초가 되면 callback하는 함수에서 창을 닫는 (아래 코드처럼)명령을 주었다. 

그랬더니 context 빨간 줄이 생기면서, initState에서 context를 사용할 수 없다는 설명이 떴다. 'initState context'를 검색해보니 context는 initState 이후에 사용할 수 있다고 한다. 그래서 해결 방법을 보니 아래 링크처럼 Future.delayed를 사용하면 된다고 한다. 그래서 따라 해보았다. 

https://stackoverflow.com/questions/49457717/flutter-get-context-in-initstate-method

 

Flutter get context in initState method

I'm not sure if the initState is the right function for this. What I'm trying to achieve is to check when the page is rendered to perform some checks and based on them opening a AlertDialog to make...

stackoverflow.com

그런데 여전히 빨간 선이 그어져있다. 설명을 보니 아래와 같았다. 

내가 argument로 넘긴 것이 Buildcontext가 아니라 Context라고? 뭐지 context가 여러 종류가 있나? 

구글링을 해보자. 

 

https://stackoverflow.com/questions/53406548/error-dart-the-argument-type-context-cant-be-assigned-to-the-parameter-typ

 

error: [dart] The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. [argument_type_not_assignable]

How can I fix this? I'm not sure if it is caused by the Flutter update.

stackoverflow.com

알고보니 Path package에 있는 context 정의와 충돌인 것을 알 수 있었다.

import 'package:path/path.dart'; 코드 위쪽에 있던 path 패키지를 Alias으로 바꾸었더니 문제가 해결 되었다. 
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함