728x90
Dart & Flutter
28

[Flutter] 빈 공간을 tap했을 때 textfield focus 해제

다음과 같이 unfocus를 사용하라는 solution을 찾았다. FocusScope.of(context).unfocus() 사용법은 간단한데 Scaffold를 GestureDetector로 Wrap하고 onTap에 적용하면 된다. GestureDetector( onTap: () => FocusScope.of(context).unfocus(), child: Scaffold( ... Scaffold 내의 child(Column과 같은)에 GestureDetector로 Wrap하고 적용하면 onTap이 적용되는 영역이 child 영역이므로 당연히 안된다. [Reference] https://github.com/flutter/flutter/issues/51621 https://stackoverflow.com/..

Dart & Flutter 2023.02.16

[Dart] ValueChanged

flutter의 doc에서는 다음과 같이 설명되어있다. Signature for callbacks that report that an underlying value has changed. typedef ValueChanged = void Function(T value); 간단히 말하면 value 값이 변경되면 함수가 실행된다는 의미이다. 아래 코드를 예시로 확인해보면 onToggleCompleted가 ValueChanged로 사용되는 부분이다. return CupertinoScrollbar( child: ListView( children: [ for (final todo in state.filteredTodos) TodoListTile( todo: todo, onToggleCompleted: (isCom..

Dart & Flutter 2023.02.16

[Flutter] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>?' in type cast

이 에러는 아마도 dynamic을 String으로 type cast해달라는 말인 것 같다. 예를 들어 다음과 같은 코드가 있다면 keywords 부분에 에러가 뜬다. KeywordCategory _$KeywordCategoryFromJson(Map json) => KeywordCategory( id: json['id'] as String?, category: json['category'] as String, keywords: json['keywords'] as List? ?? [], ); json['keywords']이 List[dynamic]이기 때문인데 이것을 .cast()으로 type cast해주면 해결된다. KeywordCategory _$KeywordCategoryFromJson(Map json..

Dart & Flutter 2023.02.15

[Flutter] BLOC: state management

Stream bloc에 대해 알기 전에 우선 stream을 알아야한다. stream을 처음 접한다면 파이프 안에 물이 흐르는 것을 생각하면 된다. 이때 파이프가 Stream이고 물이 비동기 데이터이다. 다음과 같이 stream을 사용하여 간단한 함수를 작성할 수 있다. Stream countStream(int max) async* { for (int i = 0; i < max; i++) { yield i; } } async*와 yield를 사용하여 지정한 max 파라미터 값만큼 반복해서 stream integer 값이 반환된다. 앞서 비유한 것처럼 마치 물흐르듯이 값이 나오는 것이다. 만약 stream 값들의 합을 반환하고 싶다고 한다면 다음과 같이 async와 await를 사용할 수 있다. Future..

Dart & Flutter 2023.02.07

[Flutter] The number of method references in a .dex file cannot exceed 64K.

"The number of method references in a .dex file cannot exceed 64K." 이 에러는 method가 64K를 넘었을때 나오는 에러이다. 안드로이드 기준 해결 방법은 다음과 같다. 1. build.gradle 수정 android>app>build.gradle defaultConfig { ... multiDexEnabled true } dependencies { ... implementation 'com.android.support:multidex:2.0.1' } defaultconfig에 multiDexEnabled true 를 추가해주고 dependencies에 implementation 'com.android.support:multidex:2.0.1' 를 ..

Dart & Flutter 2023.02.04

[Flutter] setstate 없이 Button 사용

ElevatedButton을 클릭하여 값을 바꿀때마다 setstate를 사용하는 경우가 있다. setstate는 refresh & reload를 해주기 때문에 다른 child widget에도 영향을 준다. 예를 들어서 child widget에 random으로 list에 있는 값을 뽑는 함수가 있다면 이 값이 버튼을 누를때마다 바뀌게 된다. 이러한 문제를 해결하기위해 ValueNotifier, ValueListenableBuilder를 사용할 것이다. 먼저 button의 initialize value 값을 정의하기위해 ValueNotifier를 사용한다. ValueNotifier dropdownValue = ValueNotifier(timeTypeList.first); List timeTypeList 그리..

Dart & Flutter 2023.01.30

[Flutter] VSCode Settings

VSCode에서 Flutter를 사용할때 다음과 같이 Setting을 적용하면 좀 더 편하게 개발할 수 있다. Ctrl + Shift + P > Preferences: Open User Settings (JSON) 1. editor.codeActionsOnSave "[dart]": { "editor.formatOnSave": true, "editor.formatOnType": true, "editor.rulers": [ 80 ], "editor.selectionHighlight": false, "editor.suggest.snippetsPreventQuickSuggestions": false, "editor.suggestSelection": "first", "editor.tabCompletion": "o..

Dart & Flutter 2023.01.15

[Flutter] Installation (Windows)

https://docs.flutter.dev/get-started/install/windows Windows install How to install on Windows. docs.flutter.dev Get the Flutter SDK 위 링크를 타고 들어가면 다음과 같이 flutter_windows_3.3.10-stable.zip 을 다운로드 받을 수 있다. 압축을 풀면 flutter라는 폴더가 있을텐데 이 폴더를 C:\src 폴더에 넣어준다. (src 폴더가 없으면 만들어준다.) flutter/bin의 full path를 확인하고 환경변수 > 사용자 변수 Path에 추가한다. 아래와 같은 path라면 C:\src\flutter\bin을 Path에 추가해주면 된다. PowerShell로 C:\src\..

Dart & Flutter 2023.01.14
728x90