avatarsimbu

Summary

The provided content discusses the process of theming a Flutter application for iOS, including the implementation of light and dark themes, and adapting the app for a white-label rebranding as EE, with a focus on maintaining flexibility and adherence to design guidelines.

Abstract

The article outlines a comprehensive approach to theming a Flutter application for iOS platforms, emphasizing the importance of creating both light and dark themes to enhance user experience. The author begins by demonstrating how to define a Cupertino light theme in a separate file and apply it to the main application file. The process involves setting primary colors and removing specific color settings to adopt the theme consistently. The article then addresses the challenge of implementing a dark theme, highlighting the need to adjust text styles to ensure readability against dark backgrounds. A switch mechanism is introduced to toggle between light and dark modes within the application state. The author further explores the concept of white-label branding by customizing the app's theme to align with EE's brand colors and typography, showcasing the final result with screenshots. The article underscores the significance of theming at the application level rather than using specific styles in individual widgets, ensuring ease of rebranding and maintenance. Additional considerations, such as automatic theme toggling based on device settings and handling themes across different platforms, are mentioned as future improvements. The author also reflects on the learning process, emphasizing the importance of experimentation and adaptation when working with new technology.

Opinions

  • The author values a maintainable and flexible approach to theming, which allows for easy rebranding of the application.
  • There is an appreciation for the design guidelines set by Apple, particularly in the implementation of text styles that adhere to Apple's Typography guidelines.
  • The author suggests that theming should be handled at the application level to avoid cluttering widgets with specific styles.
  • The process of theming is seen as an iterative learning experience, with the author advocating for hands-on experimentation with technology.
  • The article conveys a positive attitude towards embracing new challenges, such as implementing dark mode and white-label branding, as opportunities for growth and innovation.
Join Medium to view all my articles.

Flutter for iOS-Themes

Lets theme the the application, make it look good, do it in a maintainable way that can be easily rebranded.

I started by adding a ‘light’ theme in its own file:

Cupertino light theme files
import 'package:flutter/cupertino.dart';

const CupertinoThemeData cupertinoLight = CupertinoThemeData(
  brightness: Brightness.light,
  primaryColor: CupertinoColors.activeBlue
);

And using it in the main.dart file:

return CupertinoApp(
  ...  
  theme: cupertinoLight,
  ...
);

We can then remove the colour settings that were added to get the initial green background for the tab.

Digests tab — Cupertino Light Theme
Recipe Search — Cupertino Light Theme

Ok, what about a dark theme ?

import 'package:flutter/cupertino.dart';

const CupertinoThemeData cupertinoLight = CupertinoThemeData(
  brightness: Brightness.dark,
  primaryColor: CupertinoColors.activeGreen
);
Digests tab — Cupertino Dark Theme, missing text

Black text on a black background a little disappointing.

To fix this I created the text styles needed and added a switch(bool) to the application state file ‘DigestableMeState’ to control the switching between the light and dark modes.

Digests tab — Cupertino Dark Theme
Recipe search — Cupertino Dark Theme

Ok, now we look like some of Apple’s iOS applications, but what if we want to rebrand our application for EE ?

What is a white label?

In mobile applications you don’t usual need to include the logo in the application screens as its identity is the app you install, so we can just concentrate of a swatch of colours and the typography.

EE Swatch & Typography

A few more files and constants later…

EE Colours
Provider(
	create: (context) => DigestableMeState(
    	brightness: Brightness.dark,
        whiteLabel: WhiteLabel.ee
    ),
),

and we launch as EE in evening dark mode.

Digests tab — EE Dark Theme
Recipe search — EE Dark Theme

It is really about being flexible to change styles at the application level without having too may specific styles in the widgets themselves.

BackBurner

  • Automatically toggling between light and dark mode based on the current device setting.
  • Handling themes across platform to include Android or the web.
  • Custom widgets themes for custom widgets, not even sure if they are necessary at this point so something to come back to. A custom widget theme would allow you to target the custom widgets with styles i.e. we could target the all ListItem widgets to add border, padding or other styles as the application level.

XP

Getting the dark theme to work required more effort than just having a top level theme.

I had to remove the Card from the ListItem widget and go back to simple Rows, Columns, which is really what I should have used in the first place.

I replaced text styles that I had specified in the widgets

style: const TextStyle(
	color: Colors.black87,
    fontSize: 14,
),

With text styles that I created to support the Apple Typography guidelines:

Apple default text styles

Injection:

Provider(
	create: (context) => DigestableMeState(
    	brightness: Brightness.light,
    ),
)

Construction:

DigestableMeState({Brightness? brightness}) {
    if (brightness != null) {
      this.brightness = brightness;
    }
    _cupertinoTypography = CupertinoTypography(this.brightness);
...

Definition:

CupertinoTypography(this.brightness);

TextStyle bodyLight = const TextStyle(
  color: CupertinoColors.black,
  fontSize: 17,
);

TextStyle bodyDark = const TextStyle(
  color: CupertinoColors.white,
  fontSize: 17,
);
TextStyle get body {
  return brightness == Brightness.dark ? bodyDark : bodyLight;
}
...

Usage:

var appState = Provider.of<DigestableMeState>(context);
Text(item.title, style: appState.cupertinoTypography.title3)

Links

Sound & Vision

It’s only love with a little be of rain…

Carnage by Nick Cave & Warren Ellis.

One more thing

“Older people sit down and ask, ‘What is it?’ but the boy asks, ‘What can I do with it?’”

Steve Jobs_ on showing a 9-year-old a Mac

Great quote, reminds me to play with new tech, make mistakes, learn, rather than try to define or control it.

Flutter
Programming
Dart
Mobile
iOS
Recommended from ReadMedium