Skip to content

Commit c88b30b

Browse files
committed
added themes, get
1 parent 5c5f252 commit c88b30b

File tree

4 files changed

+122
-14
lines changed

4 files changed

+122
-14
lines changed

lib/main.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:get/get.dart';
3+
import 'package:symptom_tracker/theme.dart';
24

35
void main() {
46
runApp(MyApp());
@@ -8,18 +10,17 @@ class MyApp extends StatelessWidget {
810
// This widget is the root of your application.
911
@override
1012
Widget build(BuildContext context) {
11-
return MaterialApp(
13+
return GetMaterialApp(
1214
title: 'Flutter Demo',
13-
theme: ThemeData(
14-
primarySwatch: Colors.green,
15-
visualDensity: VisualDensity.adaptivePlatformDensity,
16-
),
15+
theme: appTheme(),
1716
home: Scaffold(
1817
appBar: AppBar(
1918
title: Text('Home Screen'),
2019
),
21-
body: Center(
22-
child: Text('Home Screen'),
20+
body: SafeArea(
21+
child: Center(
22+
child: Text('Home Screen'),
23+
),
2324
),
2425
),
2526
);

lib/theme.dart

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import 'package:flutter/material.dart';
2+
3+
ThemeData appTheme() {
4+
final TextTheme textTheme = _buildTextTheme();
5+
final IconThemeData iconTheme = _buildIconTheme();
6+
7+
return ThemeData.light().copyWith(
8+
// Added in Flutter 1.17
9+
visualDensity: VisualDensity.adaptivePlatformDensity,
10+
11+
// Set default colors
12+
primaryColor: _AppColors.primary,
13+
accentColor: _AppColors.secondary,
14+
disabledColor: _AppColors.disabled,
15+
errorColor: _AppColors.error,
16+
17+
// Customize Themes
18+
appBarTheme: _buildAppBarTheme(textTheme),
19+
iconTheme: iconTheme,
20+
primaryIconTheme: iconTheme.copyWith(color: _AppColors.primary),
21+
22+
// Misc
23+
buttonTheme: ButtonThemeData(
24+
buttonColor: _AppColors.primary,
25+
textTheme: ButtonTextTheme.primary,
26+
),
27+
unselectedWidgetColor: _AppColors.disabledWidget,
28+
textTheme: textTheme.apply(
29+
displayColor: _AppColors.primary,
30+
bodyColor: _AppColors.primary,
31+
),
32+
);
33+
}
34+
35+
/// ******* Colors *******
36+
class _AppColors {
37+
// Core
38+
// static const Color primary = Colors.green;
39+
static const Color primary = Color(0xFF042240);
40+
static const Color secondary = Color(0xFF018786);
41+
static Color error = Colors.red;
42+
static Color disabled = Colors.grey[500];
43+
static Color disabledWidget = Colors.grey[300];
44+
}
45+
46+
/// ******* Custom Themes *******
47+
AppBarTheme _buildAppBarTheme(TextTheme textTheme) {
48+
return AppBarTheme(
49+
textTheme: textTheme.apply(displayColor: _AppColors.primary),
50+
);
51+
}
52+
53+
IconThemeData _buildIconTheme() {
54+
return const IconThemeData(color: _AppColors.primary, size: 32);
55+
}
56+
57+
/// ******* Text Theme *******
58+
TextTheme _buildTextTheme() {
59+
return TextTheme(
60+
// Using default Material theme system
61+
// spec: https://material.io/design/typography/the-type-system.html#type-scale
62+
// on next stable release of Dart, display4 will be renamed to headline 1,
63+
// display 3 -> headline2, display2 -> headline3, etc.
64+
65+
headline1: _AppTypography.h1,
66+
headline2: _AppTypography.h2,
67+
// Dashboard: Good day // Home: Hello world
68+
headline3: _AppTypography.h3,
69+
// CheckIn: Please select symptoms
70+
headline4: _AppTypography.h4,
71+
// CheckIn: Yesterday, you had..
72+
headline5: _AppTypography.h5,
73+
// AppBar
74+
headline6: _AppTypography.h6,
75+
// ListTitle override 1
76+
subtitle1: _AppTypography.subtitle1,
77+
// ListTitle override 2
78+
subtitle2: _AppTypography.subtitle2,
79+
bodyText1: _AppTypography.bodyText1,
80+
// Default: Text Widget
81+
bodyText2: _AppTypography.bodyText2,
82+
// Default: Input error text
83+
caption: _AppTypography.caption,
84+
// Default: Button
85+
button: _AppTypography.button,
86+
overline: _AppTypography.overline,
87+
);
88+
}
89+
90+
/// ******* Custom Text *******
91+
class _AppTypography {
92+
static const TextStyle h1 = TextStyle(fontSize: 96, fontWeight: FontWeight.w100);
93+
static const TextStyle h2 = TextStyle(fontSize: 60, fontWeight: FontWeight.w100);
94+
static const TextStyle h3 = TextStyle(fontSize: 32, fontWeight: FontWeight.w800);
95+
static const TextStyle h4 = TextStyle(fontSize: 24, fontWeight: FontWeight.w800);
96+
static const TextStyle h5 = TextStyle(fontSize: 20, fontWeight: FontWeight.w400);
97+
static const TextStyle h6 = TextStyle(fontSize: 22, fontWeight: FontWeight.bold);
98+
static const TextStyle subtitle1 = TextStyle(fontSize: 20, fontWeight: FontWeight.bold);
99+
static const TextStyle subtitle2 = TextStyle(fontSize: 18, fontWeight: FontWeight.w300);
100+
static const TextStyle bodyText1 = TextStyle(fontSize: 16, fontWeight: FontWeight.normal);
101+
static const TextStyle bodyText2 = TextStyle(fontSize: 36, fontWeight: FontWeight.normal);
102+
static const TextStyle caption = TextStyle(fontSize: 12, fontWeight: FontWeight.normal);
103+
static const TextStyle button = TextStyle(fontSize: 20, fontWeight: FontWeight.w400);
104+
static const TextStyle overline = TextStyle(fontSize: 10, fontWeight: FontWeight.normal);
105+
}

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ packages:
6060
description: flutter
6161
source: sdk
6262
version: "0.0.0"
63+
get:
64+
dependency: "direct main"
65+
description:
66+
name: get
67+
url: "https://pub.dartlang.org"
68+
source: hosted
69+
version: "2.0.10"
6370
matcher:
6471
dependency: transitive
6572
description:

pubspec.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1818
version: 1.0.0+1
1919

2020
environment:
21-
sdk: ">=2.7.0 <3.0.0"
21+
sdk: '>=2.7.0 <3.0.0'
2222

2323
dependencies:
2424
flutter:
2525
sdk: flutter
26-
26+
get: ^2.0.10
2727

2828
# The following adds the Cupertino Icons font to your application.
2929
# Use with the CupertinoIcons class for iOS style icons.
@@ -38,23 +38,18 @@ dev_dependencies:
3838

3939
# The following section is specific to Flutter.
4040
flutter:
41-
4241
# The following line ensures that the Material Icons font is
4342
# included with your application, so that you can use the icons in
4443
# the material Icons class.
4544
uses-material-design: true
46-
4745
# To add assets to your application, add an assets section, like this:
4846
# assets:
4947
# - images/a_dot_burr.jpeg
5048
# - images/a_dot_ham.jpeg
51-
5249
# An image asset can refer to one or more resolution-specific "variants", see
5350
# https://flutter.dev/assets-and-images/#resolution-aware.
54-
5551
# For details regarding adding assets from package dependencies, see
5652
# https://flutter.dev/assets-and-images/#from-packages
57-
5853
# To add custom fonts to your application, add a fonts section here,
5954
# in this "flutter" section. Each entry in this list should have a
6055
# "family" key with the font family name, and a "fonts" key with a

0 commit comments

Comments
 (0)