728x90
문제 상황...
https://github.com/zubairehman/flutter_boilerplate_project/tree/master
위 깃허브의 booler plate를 공부해보고자 git을 clone해와 공부를 할려고 하던 도중 만나게 된 이슈 상황 중 하나였다
플러터가 버젼이 2에서 3으로 업그레이드가 된 것은 다들 알고 있을 것이다
최근에 나도 2에서 3으로 업그레이드 한 버젼을 사용중에 있는데. 거기서 겪게 되고 있는 이슈 상황들을 정리해 보겠다
Text Theme 부터 오류...
일단 Text Theme에서 오류가 나길래 확인을 해보았다
/// Creating custom color palettes is part of creating a custom app. The idea is to create
/// your class of custom colors, in this case `CompanyColors` and then create a `ThemeData`
/// object with those colors you just defined.
///
/// Resource:
/// A good resource would be this website: http://mcg.mbitson.com/
/// You simply need to put in the colour you wish to use, and it will generate all shades
/// for you. Your primary colour will be the `500` value.
///
/// Colour Creation:
/// In order to create the custom colours you need to create a `Map<int, Color>` object
/// which will have all the shade values. `const Color(0xFF...)` will be how you create
/// the colours. The six character hex code is what follows. If you wanted the colour
/// #114488 or #D39090 as primary colours in your setting, then you would have
/// `const Color(0x114488)` and `const Color(0xD39090)`, respectively.
///
/// Usage:
/// In order to use this newly created setting or even the colours in it, you would just
/// `import` this file in your project, anywhere you needed it.
/// `import 'path/to/setting.dart';`
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class AppThemeData {
static const _lightFillColor = Colors.black;
static const _darkFillColor = Colors.white;
static final Color _lightFocusColor = Colors.black.withOpacity(0.12);
static final Color _darkFocusColor = Colors.white.withOpacity(0.12);
static ThemeData lightThemeData =
themeData(lightColorScheme, _lightFocusColor);
static ThemeData darkThemeData = themeData(darkColorScheme, _darkFocusColor);
static ThemeData themeData(ColorScheme colorScheme, Color focusColor) {
return ThemeData(
colorScheme: colorScheme,
textTheme: _textTheme,
// Matches manifest.json colors and background color.
primaryColor: const Color(0xFF030303),
appBarTheme: AppBarTheme(
backgroundColor: colorScheme.background,
elevation: 0,
iconTheme: IconThemeData(color: colorScheme.primary),
),
iconTheme: IconThemeData(color: colorScheme.onPrimary),
canvasColor: colorScheme.background,
scaffoldBackgroundColor: colorScheme.background,
highlightColor: Colors.transparent,
focusColor: focusColor,
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
backgroundColor: Color.alphaBlend(
_lightFillColor.withOpacity(0.80),
_darkFillColor,
),
contentTextStyle: _textTheme.subtitle1!.apply(color: _darkFillColor),
),
);
}
static const ColorScheme lightColorScheme = ColorScheme(
primary: Color(0xFFd21e1d),
primaryContainer: Color(0xFF9e1718),
secondary: Color(0xFFEFF3F3),
secondaryContainer: Color(0xFFFAFBFB),
background: Color(0xFFE6EBEB),
surface: Color(0xFFFAFBFB),
onBackground: Colors.white,
error: _lightFillColor,
onError: _lightFillColor,
onPrimary: _lightFillColor,
onSecondary: Color(0xFF322942),
onSurface: Color(0xFF241E30),
brightness: Brightness.light,
);
static const ColorScheme darkColorScheme = ColorScheme(
primary: Color(0xFFFF8383),
primaryContainer: Color(0xFF1CDEC9),
secondary: Color(0xFF4D1F7C),
secondaryContainer: Color(0xFF451B6F),
background: Color(0xFF241E30),
surface: Color(0xFF1F1929),
onBackground: Color(0x0DFFFFFF),
// White with 0.05 opacity
error: _darkFillColor,
onError: _darkFillColor,
onPrimary: _darkFillColor,
onSecondary: _darkFillColor,
onSurface: _darkFillColor,
brightness: Brightness.dark,
);
static const _regular = FontWeight.w400;
static const _medium = FontWeight.w500;
static const _semiBold = FontWeight.w600;
static const _bold = FontWeight.w700;
static final TextTheme _textTheme = TextTheme(
headline4: GoogleFonts.montserrat(fontWeight: _bold, fontSize: 20.0),
caption: GoogleFonts.oswald(fontWeight: _semiBold, fontSize: 16.0),
headline5: GoogleFonts.oswald(fontWeight: _medium, fontSize: 16.0),
subtitle1: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 16.0),
overline: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 12.0),
bodyText1: GoogleFonts.montserrat(fontWeight: _regular, fontSize: 14.0),
subtitle2: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 14.0),
bodyText2: GoogleFonts.montserrat(fontWeight: _regular, fontSize: 16.0),
headline6: GoogleFonts.montserrat(fontWeight: _bold, fontSize: 16.0),
button: GoogleFonts.montserrat(fontWeight: _semiBold, fontSize: 14.0),
);
}
위에서 무엇이 문제였을까?
간단하다 저 TextTheme에 해당하는 모든 파라미터들이 에러를 내뱉고 있었다...
원인
원인은 간단하였다. 플러터가 버젼을 3로 올리면서 파라미터 명을 전부 변경한 것이였다...
(왜지?)
그럼 일치를 어떻게 시켜야 하는지 찾아보았다
기존 스타일새로운 스타일
이전 | 현재 |
headline4 | displaySmall |
headline5 | headlineSmall |
headline6 | titleLarge |
subtitle1 | titleMedium |
subtitle2 | bodySmall |
bodyText1 | bodyMedium |
bodyText2 | bodyLarge |
caption | titleMedium |
overline | labelSmall |
button | labelLarge |
그럼 하나씩 일치하는 것으로 고쳐보자
수정
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class AppThemeData {
static const _lightFillColor = Colors.black;
static const _darkFillColor = Colors.white;
static final Color _lightFocusColor = Colors.black.withOpacity(0.12);
static final Color _darkFocusColor = Colors.white.withOpacity(0.12);
static ThemeData lightThemeData =
themeData(lightColorScheme, _lightFocusColor);
static ThemeData darkThemeData = themeData(darkColorScheme, _darkFocusColor);
static ThemeData themeData(ColorScheme colorScheme, Color focusColor) {
return ThemeData(
colorScheme: colorScheme,
textTheme: _textTheme,
// Matches manifest.json colors and background color.
primaryColor: const Color(0xFF030303),
appBarTheme: AppBarTheme(
backgroundColor: colorScheme.background,
elevation: 0,
iconTheme: IconThemeData(color: colorScheme.primary),
),
iconTheme: IconThemeData(color: colorScheme.onPrimary),
canvasColor: colorScheme.background,
scaffoldBackgroundColor: colorScheme.background,
highlightColor: Colors.transparent,
focusColor: focusColor,
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
backgroundColor: Color.alphaBlend(
_lightFillColor.withOpacity(0.80),
_darkFillColor,
),
contentTextStyle: _textTheme.bodyLarge!.apply(color: _darkFillColor),
),
);
}
static const ColorScheme lightColorScheme = ColorScheme(
primary: Color(0xFFd21e1d),
primaryContainer: Color(0xFF9e1718),
secondary: Color(0xFFEFF3F3),
secondaryContainer: Color(0xFFFAFBFB),
background: Color(0xFFE6EBEB),
surface: Color(0xFFFAFBFB),
onBackground: Colors.white,
error: _lightFillColor,
onError: _lightFillColor,
onPrimary: _lightFillColor,
onSecondary: Color(0xFF322942),
onSurface: Color(0xFF241E30),
brightness: Brightness.light,
);
static const ColorScheme darkColorScheme = ColorScheme(
primary: Color(0xFFFF8383),
primaryContainer: Color(0xFF1CDEC9),
secondary: Color(0xFF4D1F7C),
secondaryContainer: Color(0xFF451B6F),
background: Color(0xFF241E30),
surface: Color(0xFF1F1929),
onBackground: Color(0x0DFFFFFF),
// White with 0.05 opacity
error: _darkFillColor,
onError: _darkFillColor,
onPrimary: _darkFillColor,
onSecondary: _darkFillColor,
onSurface: _darkFillColor,
brightness: Brightness.dark,
);
static const _regular = FontWeight.w400;
static const _medium = FontWeight.w500;
static const _semiBold = FontWeight.w600;
static const _bold = FontWeight.w700;
static final TextTheme _textTheme = TextTheme(
displaySmall: GoogleFonts.montserrat(fontWeight: _bold, fontSize: 20.0),
titleMedium: GoogleFonts.oswald(fontWeight: _semiBold, fontSize: 16.0),
titleSmall: GoogleFonts.oswald(fontWeight: _medium, fontSize: 16.0),
titleLarge: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 16.0),
labelSmall: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 12.0),
bodyMedium: GoogleFonts.montserrat(fontWeight: _regular, fontSize: 14.0),
bodySmall: GoogleFonts.montserrat(fontWeight: _medium, fontSize: 14.0),
bodyLarge: GoogleFonts.montserrat(fontWeight: _regular, fontSize: 16.0),
headlineSmall: GoogleFonts.montserrat(fontWeight: _bold, fontSize: 16.0),
labelLarge: GoogleFonts.montserrat(fontWeight: _semiBold, fontSize: 14.0),
);
}
고쳐보았다. ( 제대로 고친건가? )
그럼 이제... 기존에 사용하던 것들도 전부 하나씩 고쳐주자 ㅠ...
그러면 이렇게 실행이 되는 것을 확인 할 수 있다
'Flutter' 카테고리의 다른 글
[Flutter] flutter_native_splash 적용 안된 이유 (1) | 2024.07.14 |
---|---|
[Dart] vscode - 저장시 자동 세미 콜론 붙이기 (1) | 2024.07.14 |
댓글