디자인하다보면 css처럼 코드가 많아지는데
웹 개발에서 style.css 파일 불러오는 것 처럼 미리 디자인 파일을 작성하여 불러와보자.
import 'package:flutter/material.dart';
//다른 파일에서 쓸 수 없는 문법
//var _var1;
var theme =
ThemeData(
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
backgroundColor: Colors.grey,
)
),//버튼 스타일
appBarTheme: AppBarTheme(
color: Colors.white,
elevation: 1,
titleTextStyle: TextStyle(color: Colors.black, fontSize: 25),
actionsIconTheme: IconThemeData(color: Colors.black,),
),
textTheme: TextTheme(
bodyText2: TextStyle(color: Colors.black),
bodyText1: TextStyle(color: Colors.blue),
),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
selectedItemColor: Colors.black,
unselectedItemColor: Colors.grey,
),
);
import 'package:flutter/material.dart';
import './style.dart' as style; //style.dart를 style 이라는 변수에 담겠다.
void main() {
runApp(
MaterialApp(
theme: style.theme, //디자인 테마를 style.dart파일안에 있는 theme변수를 불러와 적용한다.
home: MyApp()
)
);
}
...이하 생략