티스토리 뷰
버튼을 클릭하면, 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가 여러 종류가 있나?
구글링을 해보자.
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 정의와 충돌인 것을 알 수 있었다.
'Dart & Flutter > 궁금했던 것, 몰랐던 것' 카테고리의 다른 글
Singletone Pattern (0) | 2022.05.27 |
---|---|
Flutter에서 Bluetooth(BLE)를 사용하기 (5) | 2022.05.10 |
List를 하나의 string으로 변환하기 (Serialization) (0) | 2022.04.20 |
Flutter 에서 사용 되는 Size의 단위 (0) | 2022.03.30 |
Stack 안에서 pixel단위가 아닌 percentage(ratio)로 위젯을 위치시키는 방법 (0) | 2022.01.19 |
- Total
- Today
- Yesterday
- Bluetooth
- UX
- 플러터
- UI
- Chrome
- hide
- plugin
- error
- TextFormField
- 이미지
- TextField
- DART
- 디자인
- 인사이트
- 다트
- 문제 해결
- firebase
- 앱개발
- SizedBox
- position
- IOS
- Flutter
- 앱 프로그래밍
- 앱
- 크롬
- BLE
- Syncfusion
- 한빛미디어
- addPostFrameCallback
- 에러
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |