🐦 Flutter 23

[Dart] Factory Constructor

Factory Constructor Factory Constructor 는 특이하게도 메서드처럼 바디가 있음 무조건 현재 클래스의 인스턴스를 반환해줘야 함 void main(){ final parent = Parent(id: 1); print(parent.id); final child = Child(id: 3); print(child.id); } class Parent { final int id; Parent({ required this.id, }); factory Parent(int id) { return Parent(id: id); // error } } class Child extends Parent { Child({ required super.id, }); } 하지만 에러가 나는 것을 볼 수 있다..

🐦 Flutter 2022.12.11

[Dart] 슈퍼 이니셜라이저

Dart 2.17 부터 새로운 단축 구문을 사용하여 생성자 매개변수를 슈퍼클래스에 전달할 수 있습니다. 참고로 이전 구문은 다음과 같습니다. class Person { Person(this.name); final String name; } // Old way: before Dart 2.17 class Employee extends Person { Employee(String name, this.salary) : super(name); final int salary; } 즉 부모 생성자에 인수를 전달하기 위해 super 를 명시적으로 호출해야 했습니다. Dart 2.17 부터 다음과 같이 할 수 있습니다. // New way: Dart 2.17 and above class Employee extends P..

🐦 Flutter 2022.12.11

[Flutter] 푸시 알람 눌렀을 때 다른 페이지로 이동

스타트업 다니면서 많은 프로젝트를 해왔지만 이번 기능(프로젝트라고 하기엔 애매함😅) 은 기록을 남기고 싶어서 글을 작성하게 되었다. 예시 코드가 없었기 때문에 개인적으로 어려웠고 구현은 해봤지만 이게 맞는 방법인지는 모른다. 하지만 그동안 내가 사용한 어플들에서 푸시 알람이 오고 눌렀을 때 다른 페이지로 가는 방법이 어떤 방식인지 알 수 있게 되어서 정말 신기했다..! 그래서 이 신기함(?)의 느낌을 기록하고 싶다..ㅎㅎ 처음에는 간단하다고 생각했다. 그리고 나는 예전에 한 번 호기심으로 깃허브 레포를 파서 푸시 알람 오게 만드는 것도 연습해봤기 때문에 금방 끝날 것이라고 생각했다. 그런데 생각보다 그리 간단하지 않았다. 아무 페이지 없는 상태에서 푸시 알람 오게 만들기는 쉬웠지만 기존 프로젝트에서 푸시..

🐦 Flutter 2022.11.17

[Flutter] Statusbar color 화면마다 다르게 적용

와이파이, 시간, 배터리가 표시되어 있는 상태바 Color 를 변경하는 방법 1. 안드로이드 appBar 안에 다음 코드를 넣는다 systemOverlayStyle: const SystemUiOverlayStyle( statusBarColor: Colors.white, statusBarIconBrightness: Brightness.dark, ), 배경 흰색, 아이콘들은 검정색 2. iOS appBar 안에 다음 코드를 추가한다 systemOverlayStyle: const SystemUiOverlayStyle( statusBarColor: Colors.white, statusBarIconBrightness: Brightness.dark, statusBarBrightness: Brightness.ligh..

🐦 Flutter 2022.09.26

[Flutter] part 와 import 차이를 알아보자

Part 와 import 차이 3개의 파일의 간단한 예시를 통해 알아보겠습니다. 1. library_main.dart library counter; export 'package:flutter/material.dart'; part 'library_part.dart'; class Counter extends AbstractCounter { // we can access library private variable _count even though it is in a different // file because we made it part of the same library reset() => _count = 0; } 첫번째 줄은 이 라이브러리의 이름을 명시해줍니다 -> counter 이것은 part 로부터..

🐦 Flutter 2022.08.20

[Flutter] 자동 생성 JSON 직렬화 코드와 비교

모델 클래스에서 JSON 직렬화 User Class 모델을 사용해보겠습니다. User Class 모델에는 map 구조에서 새로운 User 객체를 생성하기 위한 생성자인 User.fromJson() 생성자 User 객체를 map 구조로 변환하기 위한 메서드인 toJson() 메서드 class User { final String name; final String email; User(this.name, this.email); User.fromJson(Map json) : name = json['name'], email = json['email']; Map toJson() => { 'name': name, 'email': email, }; } 코드 생성 라이브러리를 통한 JSON 직렬화 여러 다른 라이브러리들..

🐦 Flutter 2022.08.20

Dart Named Constructor

Named Constructor Dart 에서 한 class 는 여러 constructor 를 가질 수 있는데, 특이한 점은 각 constructor 에 이름을 붙인다는 것이다. 명명된 생성자를 사용하여 클래스에 대해 여러 생성자를 구현하거나 추가 명확성을 제공한다. class MyPoints { final int accumulatedPoint; final int usedPoint; final int expirePoint; MyPoints({ required this.accumulatedPoint, required this.usedPoint, required this.expirePoint, }); MyPoints.initial({ this.accumulatedPoint = 0, this.usedPoint..

🐦 Flutter 2022.08.12

Flutter 생명주기

Flutter Life Cycle Widget 이론 플러터에는 Widget 단위로 개발이 된다. 이 Widget 은 불변의 법칙을 갖고 있으며 변경이 필요하면 기존 위젯을 삭제해버리고 완전히 새로운 위젯으로 대체한다. 이것이 플러터의 기본 원칙이다. Container(color: Colors.red) Container(color: Colors.blue) 예를 들어, 위처럼 Container 위젯의 color 를 red -> blue 로 바꿔었다고 해서 이는 기존 위젯을 바꾼 것이 아니라 삭제 후 새로운 위젯으로 만든 것이다. Life Cycle 이란 "생명 주기" 라는 단어 뜻에서 볼 수 있듯이 플러터에서는 위젯이 생성되고 사라질 때까지의 주기 를 관찰 해볼 것이다. 플러터에서는 대표적인 위젯 State..

🐦 Flutter 2022.07.05

[Flutter] json 파싱 정보글 모음

https://www.oowgnoj.dev/post/flutter-json [번역] 복잡한 JSON 파싱하기 in flutter 기억하기 위해 기록합니다. www.oowgnoj.dev model class 와 json 관계 이해 글 https://jvvp.tistory.com/1166 다트(dart) JSON 사용하기 dart:convert JSON 및 UTF-8 을 포함한 다양한 데이터 표현간 변환을 위한 인코더 및 디코더를 지원하는 라이브러리이다. 예제1 기본적인 JSON 문자열을 파싱하고 접근하는 방법에 대한 예제입니다. JSON jvvp.tistory.com

🐦 Flutter 2022.06.24

dart 비동기 프로그래밍

cpu thread 작업을 하는 가장 작은 단위 서버요청 때문에 cpu 가 놀게 됨 -> 굉장히 비효율적 그래서 Asynchronous Programming 이 생겨나게 됨 Stream async 를 쓰면 한번에 한 값만 받아올 수 있다. 여러 값을 받아오면 리스트를 쓰던가 등등.. stream 은 완료 될때까지 값을 계속 반환할 수 있다. stream 은 dart 에서 기본적으로 제공하는 패키지는 아니다. 패키지를 불러와서 사용해야 함 import 'dart:async'; void main() { final controller = StreamController(); // dart:async 에서 StreamController 를 가져올 수 있다 final stream = controller.stream..

🐦 Flutter 2022.06.02