diff --git a/Changelog.md b/Changelog.md index 795c72e6..3584f576 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,15 @@ # Changelog +## Unreleased + +* Nothing here + +## v1.2-beta + +* Now support dark and black themes, and also you can select the colors to theme the app as well +* Implemented NewComplaintsPage (should debug image uploading though) +* Tested on an iPad, everything works fine except the creating a new complaint. + ## v1.0-beta * Implemented SettingsPage, EventEditPage, MapPage diff --git a/lib/main.dart b/lib/main.dart index 81558710..59a56429 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -77,37 +77,34 @@ class MyAppState extends State { canvasColor: - widget.bloc.brightness == Brightness.dark ? Colors.black : null, - // bottomAppBarColor: widget.bloc.brightness == Brightness.dark - // ? Colors.grey[850] - // : null, + widget.bloc.brightness == AppBrightness.black ? Colors.black : null, bottomAppBarColor: widget.bloc.primaryColor, - brightness: widget.bloc.brightness, + brightness: widget.bloc.brightness.toBrightness(), textTheme: TextTheme( display1: TextStyle( fontFamily: "SourceSansPro", - color: widget.bloc.brightness == Brightness.light + color: widget.bloc.brightness == AppBrightness.light ? Colors.black : Colors.white, ), display2: TextStyle( fontFamily: "SourceSansPro", - color: widget.bloc.brightness == Brightness.light + color: widget.bloc.brightness == AppBrightness.light ? Colors.black : Colors.white, ), display3: TextStyle( fontFamily: "SourceSansPro", - color: widget.bloc.brightness == Brightness.light + color: widget.bloc.brightness == AppBrightness.light ? Colors.black : Colors.white, ), display4: TextStyle( fontFamily: "SourceSansPro", - color: widget.bloc.brightness == Brightness.light + color: widget.bloc.brightness == AppBrightness.light ? Colors.black : Colors.white, ), diff --git a/lib/src/blocs/ia_bloc.dart b/lib/src/blocs/ia_bloc.dart index d2ad1add..ac864fb1 100644 --- a/lib/src/blocs/ia_bloc.dart +++ b/lib/src/blocs/ia_bloc.dart @@ -18,6 +18,55 @@ import 'package:http/io_client.dart'; import 'package:jaguar_retrofit/jaguar_retrofit.dart'; import 'package:shared_preferences/shared_preferences.dart'; +/// Describes the contrast needs of a color. +class AppBrightness { + final index; + const AppBrightness._internal(this.index); + toString() => 'AppBrightness.$index'; + + /// The color is dark and will require a light text color to achieve readable + /// contrast. + /// + /// For example, the color might be dark grey, requiring white text. + + static const dark = const AppBrightness._internal(0); + + /// The color is light and will require a dark text color to achieve readable + /// contrast. + /// + /// For example, the color might be bright white, requiring black text. + + static const light = const AppBrightness._internal(1); + + /// The color is black and will require a light text color to achieve readable + /// contrast. + /// + /// For example, the color might be black, requiring white text. + static const black = const AppBrightness._internal(2); + + static const values = [dark, light, black]; + + Brightness toBrightness() { + return index == 2 ? Brightness.dark : Brightness.values[index]; + } + + // // You should generally implement operator == if you + // // override hashCode. + // @override + // bool operator ==(dynamic other) { + // if (other is! AppBrightness) { + // if (other is! Brightness) { + // return false; + // } + // Brightness brightness = other; + // return brightness.index == index || (index == 2 && brightness.index == 1); + // } + // AppBrightness appBrightness = other; + // return appBrightness.index == index; + // } + +} + class InstiAppBloc { // Different Streams for the state Stream> get hostels => _hostelsSubject.stream; @@ -50,15 +99,15 @@ class InstiAppBloc { String homepageName = "/mess"; // default theme - Brightness _brightness = Brightness.light; + AppBrightness _brightness = AppBrightness.light; // Color _primaryColor = Color.fromARGB(255, 63, 81, 181); Color _primaryColor = Color.fromARGB(255, 0, 98, 255); Color _accentColor = Color.fromARGB(255, 239, 83, 80); // Color _accentColor = Color.fromARGB(255, 139, 195, 74); - Brightness get brightness => _brightness; + AppBrightness get brightness => _brightness; - set brightness(Brightness newBrightness) { + set brightness(AppBrightness newBrightness) { if (newBrightness != _brightness) { wholeAppKey.currentState.setTheme(() => _brightness = newBrightness); SharedPreferences.getInstance().then((s) { @@ -103,7 +152,7 @@ class InstiAppBloc { '/quicklinks': 9, '/settings': 10, }; - + // MaterialApp reference GlobalKey wholeAppKey; @@ -131,7 +180,8 @@ class InstiAppBloc { drawerState.setPageIndex(pageToIndex[homepageName]); } if (prefs.getKeys().contains("brightness")) { - _brightness = Brightness.values[prefs.getInt("brightness")] ?? _brightness; + _brightness = + AppBrightness.values[prefs.getInt("brightness")] ?? _brightness; } if (prefs.getKeys().contains("accentColor")) { _accentColor = Color(prefs.getInt("accentColor")) ?? _accentColor; diff --git a/lib/src/routes/settingspage.dart b/lib/src/routes/settingspage.dart index 1d719c02..f229a71f 100644 --- a/lib/src/routes/settingspage.dart +++ b/lib/src/routes/settingspage.dart @@ -1,5 +1,6 @@ import 'package:InstiApp/src/api/model/user.dart'; import 'package:InstiApp/src/bloc_provider.dart'; +import 'package:InstiApp/src/blocs/ia_bloc.dart'; import 'package:InstiApp/src/drawer.dart'; import 'package:InstiApp/src/utils/common_widgets.dart'; import 'package:flutter/material.dart'; @@ -111,17 +112,25 @@ class _SettingsPageState extends State { .copyWith(fontWeight: FontWeight.bold), ), ), - RadioListTile( + RadioListTile( title: const Text("Light"), - value: Brightness.light, + value: AppBrightness.light, groupValue: bloc.brightness, onChanged: (v) { bloc.brightness = v; }, ), - RadioListTile( + RadioListTile( title: const Text("Dark"), - value: Brightness.dark, + value: AppBrightness.dark, + groupValue: bloc.brightness, + onChanged: (v) { + bloc.brightness = v; + }, + ), + RadioListTile( + title: const Text("Black"), + value: AppBrightness.black, groupValue: bloc.brightness, onChanged: (v) { bloc.brightness = v; diff --git a/pubspec.yaml b/pubspec.yaml index 1df3981a..394553a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ description: Flutter App for Indian Institute of Technology, Bombay # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # Read more about versioning at semver.org. -version: 1.0.0+15 +version: 1.2.0+17 environment: sdk: ">=2.0.0-dev.68.0 <3.0.0" @@ -41,7 +41,7 @@ dependencies: flutter_material_color_picker: ^0.0.3+1 flutter_typeahead: ^0.5.1 image_picker: ^0.4.12 - + dev_dependencies: flutter_test: sdk: flutter