Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
* Fixes broken changes after Merge commit with develop
Browse files Browse the repository at this point in the history
* Adds missing line break after last line of code
* Fixes bug on using describeEnum(..)
* Updates assets to new versions
* Adapts corner radius at image border according Cornelius' request
* adapts UI according to Cornelius' request
* fixes Image height
* removes code regarding convenience class 'Preference'
  • Loading branch information
Frank Gregor committed Apr 7, 2020
1 parent 57a68af commit ed5a0d9
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 83 deletions.
Binary file modified assets/images/2.0x/theme_coi_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/2.0x/theme_coi_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/2.0x/theme_coi_system.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/3.0x/theme_coi_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/3.0x/theme_coi_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/3.0x/theme_coi_system.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/theme_coi_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/theme_coi_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/theme_coi_system.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 36 additions & 38 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,32 @@ void main() {
final errorBloc = ErrorBloc();

WidgetsFlutterBinding.ensureInitialized(); // Required to allow plugin calls prior runApp() (performed by LogManager.setup())
_logManager.setup(logToFile: true, logLevel: Level.INFO);

runApp(
MultiBlocProvider(
providers: [
BlocProvider<LifecycleBloc>(
create: (BuildContext context) {
var lifecycleBloc = LifecycleBloc();
lifecycleBloc.add(ListenerSetup());
return lifecycleBloc;
},
),
BlocProvider<PushBloc>(
create: (BuildContext context) => PushBloc(),
),
BlocProvider<ErrorBloc>(
create: (BuildContext context) => errorBloc,
_logManager.setup(logToFile: true, logLevel: Level.INFO).then((value) => runApp(
MultiBlocProvider(
providers: [
BlocProvider<LifecycleBloc>(
create: (BuildContext context) {
var lifecycleBloc = LifecycleBloc();
lifecycleBloc.add(ListenerSetup());
return lifecycleBloc;
},
),
BlocProvider<PushBloc>(
create: (BuildContext context) => PushBloc(),
),
BlocProvider<ErrorBloc>(
create: (BuildContext context) => errorBloc,
),
BlocProvider<MainBloc>(
create: (BuildContext context) => MainBloc(errorBloc),
),
],
child: CustomTheme(
initialThemeKey: ThemeKey.light,
child: OxCoiApp(),
),
),
BlocProvider<MainBloc>(
create: (BuildContext context) => MainBloc(errorBloc),
),
],
child: CustomTheme(
initialThemeKey: ThemeKey.light,
child: OxCoiApp(),
),
),
);
));
}

class OxCoiApp extends StatelessWidget {
Expand All @@ -105,17 +103,17 @@ class OxCoiApp extends StatelessWidget {
Widget build(BuildContext context) {
var customTheme = CustomTheme.of(context);
final themeData = ThemeData(
brightness: customTheme.brightness,
backgroundColor: customTheme.background,
scaffoldBackgroundColor: customTheme.background,
toggleableActiveColor: customTheme.accent,
accentColor: customTheme.accent,
primaryIconTheme: Theme.of(context).primaryIconTheme.copyWith(
color: customTheme.onSurface,
),
primaryTextTheme: Theme.of(context).primaryTextTheme.apply(
bodyColor: customTheme.onSurface,
),
brightness: customTheme.brightness,
backgroundColor: customTheme.background,
scaffoldBackgroundColor: customTheme.background,
toggleableActiveColor: customTheme.accent,
accentColor: customTheme.accent,
primaryIconTheme: Theme.of(context).primaryIconTheme.copyWith(
color: customTheme.onSurface,
),
primaryTextTheme: Theme.of(context).primaryTextTheme.apply(
bodyColor: customTheme.onSurface,
),
);

return MaterialApp(
Expand Down
46 changes: 25 additions & 21 deletions lib/src/brandable/custom_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ enum ThemeKey {
dark,
}

extension ThemeKeyStrings on ThemeKey {
String get stringValue {
return describeEnum(this);
}
}

class CustomerThemes {
static final BrandedTheme lightTheme = BrandedTheme(
accent: const Color(0xFF0076FF),
Expand Down Expand Up @@ -141,9 +147,9 @@ class CustomTheme extends StatefulWidget {
}

static ThemeKey getThemeKeyFor({@required String name}) {
if (name == describeEnum(ThemeKey.system)) {
if (name == ThemeKey.system.stringValue) {
return ThemeKey.system;
} else if (name == describeEnum(ThemeKey.light)) {
} else if (name == ThemeKey.light.stringValue) {
return ThemeKey.light;
} else {
return ThemeKey.dark;
Expand All @@ -152,10 +158,7 @@ class CustomTheme extends StatefulWidget {

static ThemeKey get systemThemeKey {
final brightness = WidgetsBinding.instance.window.platformBrightness;
if (brightness == Brightness.light) {
return ThemeKey.light;
}
return ThemeKey.dark;
return brightness == Brightness.light ? ThemeKey.light : ThemeKey.dark;
}
}

Expand Down Expand Up @@ -186,14 +189,14 @@ class CustomThemeState extends State<CustomTheme> with WidgetsBindingObserver {
_checkSavedTheme();
}

void _checkSavedTheme() async {
var savedThemeKeyString = await Preference.themeKey;
Future<void> _checkSavedTheme() async {
var savedThemeKeyString = await getPreference(preferenceApplicationTheme);

ThemeKey savedThemeKey;
if (savedThemeKeyString == null) {
savedThemeKey = ThemeKey.system;
savedThemeKeyString = describeEnum(savedThemeKey);
Preference.themeKey = savedThemeKeyString;
savedThemeKeyString = savedThemeKey.stringValue;
await setPreference(preferenceApplicationTheme, savedThemeKeyString);
}

ThemeKey newThemeKey;
Expand All @@ -204,24 +207,25 @@ class CustomThemeState extends State<CustomTheme> with WidgetsBindingObserver {
newThemeKey = CustomTheme.getThemeKeyFor(name: savedThemeKeyString);
}

changeTheme(themeKey: newThemeKey, preservePreference: true);
await changeTheme(themeKey: newThemeKey, preservePreference: true);
}

void changeTheme({@required ThemeKey themeKey, bool preservePreference = false}) async {
Future<void> changeTheme({@required ThemeKey themeKey, bool preservePreference = false}) async {
setState(() {
_actualThemeKey = themeKey;
_theme = CustomerThemes.getThemeFromKey(themeKey);
});

if (!preservePreference) {
Preference.themeKey = describeEnum(themeKey);
}
if (!preservePreference) {
setPreference(preferenceApplicationTheme, themeKey.stringValue);
}

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: CustomerThemes.getThemeFromKey(themeKey).background, // Android only
statusBarIconBrightness: themeKey == ThemeKey.dark ? Brightness.light : Brightness.dark, // Android only
statusBarBrightness: themeKey == ThemeKey.dark ? Brightness.dark : Brightness.light // iOS only
));
final statusBarColor = CustomerThemes.getThemeFromKey(themeKey).background;
final statusBarIconBrightness = themeKey == ThemeKey.dark ? Brightness.light : Brightness.dark;
final statusBarBrightness = themeKey == ThemeKey.dark ? Brightness.dark : Brightness.light;

var overlayStyle = themeKey == ThemeKey.dark ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark;
SystemChrome.setSystemUIOverlayStyle(overlayStyle);
});
}

@override
Expand Down
17 changes: 1 addition & 16 deletions lib/src/platform/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const preferenceNotificationsPushStatus = "preferenceNotificationsPushStatus";
const preferenceAppState = "preferenceAppState";
const preferenceInviteServiceUrl = "preferenceInviteServiceUrl";
const preferenceHasAuthenticationError = "preferenceHasAuthenticationError";
const preferenceApplicationTheme = "preferenceApplicationTheme";

const preferenceNotificationsAuth = "preferenceNotificationsAuth"; // Unused
const preferenceNotificationsP256dhPublic = "preferenceNotificationsP256dhPublic"; // Unused
Expand Down Expand Up @@ -97,19 +98,3 @@ Future<void> clearPreferences() async {
SharedPreferences sharedPreferences = await getSharedPreferences();
await sharedPreferences.clear();
}

class Preference {

static const _themeKey = "themeKey";
static Future<String> get themeKey async => await value(forKey: _themeKey);
static set themeKey(String value) => set(value: value, forKey: _themeKey);

static set({@required value, @required String forKey}) async {
await setPreference(forKey, value);
}

static value({@required String forKey}) async {
return await getPreference(forKey);
}

}
18 changes: 11 additions & 7 deletions lib/src/settings/settings_appearance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class _AppearanceSelector extends StatelessWidget {
children: <Widget>[
Container(
margin: EdgeInsets.only(left: dimension8dp, right: dimension8dp),
padding: EdgeInsets.all(dimension16dp),
decoration: BoxDecoration(
color: selectedTheme == themeKey ? CustomTheme.of(context).surface : CustomTheme.of(context).background,
borderRadius: BorderRadius.all(Radius.circular(dimension8dp)),
Expand All @@ -169,25 +168,30 @@ class _AppearanceSelector extends StatelessWidget {
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: dimension16dp),
padding: EdgeInsets.only(bottom: dimension4dp),
child: Container(
margin: EdgeInsets.all(dimension8dp),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(dimension4dp)),
borderRadius: BorderRadius.all(Radius.circular(dimension6dp)),
border: Border.all(color: CustomTheme.of(context).onBackground.slightly()),
),
child: Image(
image: AssetImage('assets/images/theme_coi_${describeEnum(themeKey)}.png'),
image: AssetImage('assets/images/theme_coi_${themeKey.stringValue}.png'),
width: 70.0,
),
),
),
Text(
themeItemData[themeKey],
Padding(
padding: EdgeInsets.only(bottom: dimension12dp),
child: Text(
themeItemData[themeKey],
),
),
],
),
),
Padding(
padding: EdgeInsets.only(bottom: dimension16dp),
padding: EdgeInsets.only(bottom: dimension8dp),
child: Radio(
value: themeKey,
groupValue: selectedTheme,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/settings/settings_appearance_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SettingsAppearanceBloc extends Bloc<SettingsAppearanceEvent, SettingsAppea
@override
Stream<SettingsAppearanceState> mapEventToState(SettingsAppearanceEvent event) async* {
if (event is LoadAppearance) {
final themeKeyString = await Preference.themeKey;
final themeKeyString = await getPreference(preferenceApplicationTheme);
final savedThemeKey = CustomTheme.getThemeKeyFor(name: themeKeyString);
add(AppearanceLoaded(themeKey: savedThemeKey));

Expand Down
1 change: 1 addition & 0 deletions lib/src/ui/dimensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const textScaleDefault = 1.0;
// Defaults
const dimension2dp = 2.0;
const dimension4dp = 4.0;
const dimension6dp = 6.0;
const dimension8dp = 8.0;
const dimension12dp = 12.0;
const dimension16dp = 16.0;
Expand Down

0 comments on commit ed5a0d9

Please sign in to comment.