> Frontend/Flutter

Flutter_08. making a model class

Janku 2023. 5. 2. 23:14

1.

   - flutter pub add uuid 설치 후, 아래와 같이 진행 

import 'package:uuid/uuid.dart';

const uuid = Uuid();
class Expense {
  Expense({
    required this.title,
    required this.amount,
    required this.date
  }): id = uuid.v4();
  // in Dart, 'Initializer Lists' can be used to initialize class properties with values that are Not received as constructor function arguments
  // Basically, when this Expense class initialized, it will be assign as an initial value to ID property

  final String id;
  final String title;
  final double amount;

  final DateTime date;
}

 

   - 위의 사진과 같이, id 값에 초기값을 할당할 수 있다.