Skip to content

Commit

Permalink
Use custom text styles instead of text theme. (#117)
Browse files Browse the repository at this point in the history
* Use custom text styles instead of text theme.

Custom text styles are better to handle custom styles for text
throughout the app. Modifying the text theme also changes the style of
the text in the themes that are in use in the material widgets.

* nit: Made opacity double in overlineText color
  • Loading branch information
Thesmader authored Jan 26, 2021
1 parent 37fda38 commit 7d7e104
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 73 deletions.
Binary file added elaichi/assets/fonts/Inter.ttf
Binary file not shown.
93 changes: 93 additions & 0 deletions elaichi/assets/fonts/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright (c) 2016-2019 The Inter Project Authors ([email protected])

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
4 changes: 4 additions & 0 deletions elaichi/lib/app/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class AppColors {
static const Color lightBottomNav = Color.fromRGBO(255, 255, 255, 1.0);
static const Color darkBottomNav = Color.fromRGBO(23, 23, 23, 1.0);
static const Color lightAnnouncementText = Color.fromRGBO(79, 79, 79, 1.0);
static const Color bodyText = Color.fromRGBO(79, 79, 79, 1.0);
static const Color titleText = Color.fromRGBO(51, 51, 51, 1.0);
static const Color overlineText = Color.fromRGBO(130, 130, 130, 1.0);
static const Color darkAnnouncementText = Color.fromRGBO(224, 224, 224, 1.0);
static const Color darkAnnouncementDocBackground =
Color.fromRGBO(238, 109, 109, 0.05);
static const Color unselectedIconColor = Color.fromRGBO(196, 196, 196, 1.0);

//icons
static const Color calendarIcon = Color.fromRGBO(47, 128, 237, 1.0);
Expand Down
53 changes: 53 additions & 0 deletions elaichi/lib/app/styles.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:elaichi/app/colors.dart';
import 'package:flutter/widgets.dart';

/// Text styles used in the app.
class TextStyles {
/// Used in appbar title and event name in club page.
static TextStyle get title => const TextStyle(
fontSize: 18.0,
height: 1.21,
fontWeight: FontWeight.w700,
color: AppColors.titleText,
letterSpacing: -0.02);

/// Used in Section headers, Club name in club page,
/// prominent button(s)(Add Event Poster).
static TextStyle get heading1 => const TextStyle(
fontSize: 16.0, fontWeight: FontWeight.w600, height: 1.225);

/// Used in Smaller section headers, TabBar, subject/event title in schedule.
static TextStyle get heading2 =>
const TextStyle(fontSize: 14.0, height: 1.4, fontWeight: FontWeight.w600);

/// Used for Bold/grey/colored text paired with body1, course code/club,
/// time name in schedule, desgination of club members
static TextStyle get subtitle => const TextStyle(
fontSize: 12.0,
color: AppColors.bodyText,
height: 1.4,
fontWeight: FontWeight.w600);

/// Used for Body text w400 - long body text, student poll option,
/// event description, prof/event contact in schedule.
static TextStyle get body1 => const TextStyle(
fontSize: 12.0,
height: 1.4,
fontWeight: FontWeight.w400,
color: AppColors.bodyText);

/// Variant of [body1].
static TextStyle get body2 => const TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w500,
height: 1.4,
color: AppColors.bodyText);

/// Smallest font size. Used in dividers and separators.
static TextStyle get overline => const TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.w700,
height: 1.4,
color: AppColors.overlineText,
letterSpacing: -0.02);
}
67 changes: 34 additions & 33 deletions elaichi/lib/app/themes/base_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,50 @@ import 'package:elaichi/app/colors.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

/// Base text theme for the app.
final TextTheme textTheme = TextTheme(
headline1: GoogleFonts.inter(
fontSize: 93, fontWeight: FontWeight.w300, letterSpacing: -1.5),
headline2: GoogleFonts.inter(
fontSize: 58, fontWeight: FontWeight.w300, letterSpacing: -0.5),
headline3: GoogleFonts.inter(fontSize: 47, fontWeight: FontWeight.w400),
headline4: GoogleFonts.inter(
fontSize: 33, fontWeight: FontWeight.w400, letterSpacing: 0.25),
headline5: GoogleFonts.inter(fontSize: 23, fontWeight: FontWeight.w400),
headline6: GoogleFonts.inter(
fontSize: 19, fontWeight: FontWeight.w500, letterSpacing: 0.15),
subtitle1: GoogleFonts.inter(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.15),
subtitle2: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 0.1),
bodyText1: GoogleFonts.inter(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.5),
bodyText2: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w400, letterSpacing: 0.25),
button: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 1.25),
caption: GoogleFonts.inter(
fontSize: 12, fontWeight: FontWeight.w400, letterSpacing: 0.4),
overline: GoogleFonts.inter(
fontSize: 10, fontWeight: FontWeight.w400, letterSpacing: 1.5),
);

/// Base theme for the app. Custom themes can be made by using copyWith()
/// on [AppTheme.light] or [AppTheme.dark].
abstract class AppTheme {
static const Color _lightPrimaryColor = Colors.white;
static const Color _lightOnPrimaryColor = Colors.black;

/// Base text theme of the app
static final TextTheme baseTextTheme = TextTheme(
headline1: GoogleFonts.inter(
fontSize: 93, fontWeight: FontWeight.w300, letterSpacing: -1.5),
headline2: GoogleFonts.inter(
fontSize: 58, fontWeight: FontWeight.w300, letterSpacing: -0.5),
headline3: GoogleFonts.inter(fontSize: 47, fontWeight: FontWeight.w400),
headline4: GoogleFonts.inter(
fontSize: 33, fontWeight: FontWeight.w400, letterSpacing: 0.25),
headline5: GoogleFonts.inter(fontSize: 23, fontWeight: FontWeight.w400),
headline6: GoogleFonts.inter(
fontSize: 19, fontWeight: FontWeight.w500, letterSpacing: 0.15),
subtitle1: GoogleFonts.inter(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.15),
subtitle2: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 0.1),
bodyText1: GoogleFonts.inter(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.5),
bodyText2: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w400, letterSpacing: 0.25),
button: GoogleFonts.inter(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 1.25),
caption: GoogleFonts.inter(
fontSize: 12, fontWeight: FontWeight.w400, letterSpacing: 0.4),
overline: GoogleFonts.inter(
fontSize: 10, fontWeight: FontWeight.w400, letterSpacing: 1.5),
);

/// Base light theme of the app.
static final ThemeData light = ThemeData(
scaffoldBackgroundColor: AppColors.lightScaffoldBackground,
textTheme: baseTextTheme,
textTheme: textTheme,
appBarTheme: const AppBarTheme(
color: _lightPrimaryColor,
iconTheme: IconThemeData(color: _lightOnPrimaryColor)),
colorScheme: const ColorScheme.light(
primary: _lightPrimaryColor,
surface: Colors.white,
primaryVariant: _lightPrimaryColor,
secondary: _lightOnPrimaryColor,
onPrimary: _lightOnPrimaryColor,
Expand All @@ -60,17 +61,17 @@ abstract class AppTheme {
/// Base dark theme of the app.
static final ThemeData dark = ThemeData(
scaffoldBackgroundColor: AppColors.darkScaffoldBackground,
textTheme: baseTextTheme,
textTheme: textTheme,
appBarTheme: const AppBarTheme(
color: Colors.black87,
iconTheme: IconThemeData(color: _lightPrimaryColor),
color: Color.fromRGBO(27, 27, 27, 1.0),
iconTheme: IconThemeData(color: Colors.white),
),
colorScheme: const ColorScheme.dark(
primary: _lightOnPrimaryColor,
surface: Color.fromRGBO(27, 27, 27, 1.0),
primaryVariant: _lightOnPrimaryColor,
secondary: _lightPrimaryColor,
onPrimary: _lightPrimaryColor),
// iconTheme: IconThemeData(color: _iconColor),
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
Expand Down
30 changes: 0 additions & 30 deletions elaichi/lib/app/themes/text_themes.dart

This file was deleted.

7 changes: 5 additions & 2 deletions elaichi/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:elaichi/app/themes/base_theme.dart';
import 'package:elaichi/generated/codegen_loader.g.dart';
import 'package:elaichi/generated/locale_keys.g.dart';
import 'package:elaichi/ui/utils/no_over_scroll.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logger/logger.dart';
Expand All @@ -14,7 +14,10 @@ import 'package:stacked_themes/stacked_themes.dart';

Future<void> main() async {
await ThemeManager.initialise();
await Firebase.initializeApp();
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
Logger.level = Level.debug;
setupLocator(environment: Env.dev);
WidgetsFlutterBinding.ensureInitialized();
Expand Down
2 changes: 0 additions & 2 deletions elaichi/lib/ui/views/feed/feed_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class FeedView extends StatelessWidget {
appBar: ElaichiAppbar(
title: LocaleKeys.homeTitle.tr(),
appbarHeight: 76,
backgroundColor: Colors.white,
titleColor: Colors.black,
),
body: model.isBusy
? const Center(
Expand Down
13 changes: 9 additions & 4 deletions elaichi/lib/ui/views/home/home_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:elaichi/app/colors.dart';
import 'package:elaichi/ui/views/feed/feed_view.dart';
import 'package:elaichi/ui/views/home/home_viewmodel.dart';
import 'package:flutter/material.dart';
Expand All @@ -17,7 +18,10 @@ class HomeView extends StatelessWidget {
builder: (context, model, child) => Scaffold(
bottomNavigationBar: BottomNavigationBar(
currentIndex: model.currentIndex,
type: BottomNavigationBarType.fixed,
onTap: model.setIndex,
selectedItemColor: AppColors.bodyText,
unselectedItemColor: AppColors.overlineText,
items: const [
BottomNavigationBarItem(
label: 'Feed', icon: Icon(Icons.dynamic_feed)),
Expand All @@ -28,10 +32,11 @@ class HomeView extends StatelessWidget {
],
),
body: SafeArea(
child: IndexedStack(
index: model.currentIndex,
children: const [FeedView(), FeedView(), FeedView()],
)),
child: IndexedStack(
index: model.currentIndex,
children: const [FeedView(), FeedView(), FeedView()],
),
),
),
viewModelBuilder: () => HomeViewModel(),
);
Expand Down
2 changes: 1 addition & 1 deletion elaichi/lib/ui/widgets/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ElaichiAppbar extends StatelessWidget with PreferredSizeWidget {
this.elevation = 0.0,
this.centerTitle = true,
this.appbarHeight = kToolbarHeight});

/// Title to show in the appbar.
final String title;

Expand Down
3 changes: 2 additions & 1 deletion elaichi/lib/ui/widgets/story/story_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:elaichi/ui/views/feed/feed_viewmodel.dart';
import 'package:elaichi/ui/widgets/story/story_component.dart';
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'package:elaichi/app/extensions.dart';

/// Story bar displayed in FeedView.
class StoryBar extends ViewModelWidget<FeedViewModel> {
Expand All @@ -13,7 +14,7 @@ class StoryBar extends ViewModelWidget<FeedViewModel> {
return AspectRatio(
aspectRatio: 410 / 120,
child: Container(
color: Colors.white,
color: context.theme.colorScheme.surface,
child: viewModel.currentStories.fold(
(failure) => Text(failure.toString()),
(currentStories) => ListView.builder(
Expand Down
1 change: 1 addition & 0 deletions elaichi/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ flutter:
assets:
- assets/translations/
- assets/images/
- assets/fonts/

0 comments on commit 7d7e104

Please sign in to comment.