main.dart 파일에서 패키지를 임포트 해준다.
json_theme.dart는 외부 패키지이므로 pubspec.yaml 파일에 미리 등록을 해줘야 한다.
import 'package:flutter/material.dart';
import 'dart:convert'; // for jsonDecode
import 'package:flutter/services.dart'; // for rootBundle
import 'package:json_theme/json_theme.dart'; // for theme decoder
assets 폴더안에 theme.json 파일을 저장해주고, 아래와 같이 불러온다.
void main() async {
// 테마데이터 실행 _ from json_theme, asset
WidgetsFlutterBinding.ensureInitialized();
final themeStr = await rootBundle.loadString('assets/theme.json');
final themeJson = jsonDecode(themeStr);
final theme = ThemeDecoder.decodeThemeData(themeJson);
final ThemeData? customTheme = theme;
materialapp 에서 theme를 불러온다. (여기서는 Get 패키지를 사용)
child: GetMaterialApp(
scrollBehavior: AppScrollBehavior(),
home: MePage0(),
debugShowCheckedModeBanner: false,
theme: customeTheme,
),
이제 사용을 해주면 된다. json theme를 제작할 수 있는 사이트는 아래 사이트밖에 모르겠다.
끝.
'Dead Code > Flutter_Dart' 카테고리의 다른 글
[플러터] 심플 애니메이션 (0) | 2023.07.20 |
---|---|
[플러터] minSdkVersion 위치 (0) | 2023.07.18 |
[다트] 리스트 중복 제거 (0) | 2023.07.14 |
[플러터] Map 정렬하기 (0) | 2023.07.12 |
[플러터] 구글 Sheets 를 DB로 사용해서 갤러리 만들기 #2 (0) | 2023.07.12 |
[플러터] widget : Wrap (0) | 2023.07.06 |
[플러터] package : fluttertoast (0) | 2023.06.26 |
[다트] dart 3.0 - records 괄호 지옥 (0) | 2023.05.26 |
[플러터] 구글 Sheets 를 DB로 사용해서 갤러리 만들기 #1 (0) | 2023.05.11 |
[플러터] Rive animation 실행은 해보자 #2 (0) | 2023.04.24 |