From 3105ed6c1d67645d76f608b46e3abbf1335f0eec Mon Sep 17 00:00:00 2001 From: exttex Date: Sun, 21 Mar 2021 22:46:44 +0100 Subject: [PATCH] Display mode --- lib/languages/en_us.dart | 5 ++++- lib/main.dart | 8 ++++++++ lib/settings.dart | 2 ++ lib/settings.g.dart | 2 ++ lib/ui/login_screen.dart | 2 +- lib/ui/settings_screen.dart | 27 +++++++++++++++++++++++++++ pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 8 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/languages/en_us.dart b/lib/languages/en_us.dart index cdd43de..ed5660f 100644 --- a/lib/languages/en_us.dart +++ b/lib/languages/en_us.dart @@ -348,6 +348,9 @@ const language_en_us = { "Email": "Email", "Missing email or password!": "Missing email or password!", "Error logging in using email, please check your credentials.\nError:": "Error logging in using email, please check your credentials.\nError:", - "Error logging in!": "Error logging in!" + "Error logging in!": "Error logging in!", + "Change display mode": "Change display mode", + "Enable high refresh rates": "Enable high refresh rates", + "Display mode": "Display mode" } }; diff --git a/lib/main.dart b/lib/main.dart index fa6e202..b51c671 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:custom_navigator/custom_navigator.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_displaymode/flutter_displaymode.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:freezer/api/cache.dart'; import 'package:freezer/api/definitions.dart'; @@ -175,6 +176,13 @@ class _MainScreenState extends State with SingleTickerProviderStateM void initState() { navigatorKey = GlobalKey(); + //Set display mode + if (settings.displayMode != null) { + FlutterDisplayMode.supported.then((modes) async { + FlutterDisplayMode.setMode(modes[settings.displayMode]); + }); + } + _startStreamingServer(); //Start with parameters diff --git a/lib/settings.dart b/lib/settings.dart index 94d391c..46f0af6 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -97,6 +97,8 @@ class Settings { String font; @JsonKey(defaultValue: false) bool lyricsVisualizer; + @JsonKey(defaultValue: null) + int displayMode; //Colors @JsonKey(toJson: _colorToJson, fromJson: _colorFromJson) diff --git a/lib/settings.g.dart b/lib/settings.g.dart index 28b712b..e7504be 100644 --- a/lib/settings.g.dart +++ b/lib/settings.g.dart @@ -68,6 +68,7 @@ Settings _$SettingsFromJson(Map json) { ..blurPlayerBackground = json['blurPlayerBackground'] as bool ?? false ..font = json['font'] as String ?? 'Deezer' ..lyricsVisualizer = json['lyricsVisualizer'] as bool ?? false + ..displayMode = json['displayMode'] as int ..primaryColor = Settings._colorFromJson(json['primaryColor'] as int) ..useArtColor = json['useArtColor'] as bool ?? false ..deezerLanguage = json['deezerLanguage'] as String ?? 'en' @@ -109,6 +110,7 @@ Map _$SettingsToJson(Settings instance) => { 'blurPlayerBackground': instance.blurPlayerBackground, 'font': instance.font, 'lyricsVisualizer': instance.lyricsVisualizer, + 'displayMode': instance.displayMode, 'primaryColor': Settings._colorToJson(instance.primaryColor), 'useArtColor': instance.useArtColor, 'deezerLanguage': instance.deezerLanguage, diff --git a/lib/ui/login_screen.dart b/lib/ui/login_screen.dart index b3aa86b..422acc6 100644 --- a/lib/ui/login_screen.dart +++ b/lib/ui/login_screen.dart @@ -344,7 +344,7 @@ class _EmailLoginState extends State { String _password; bool _loading = false; - void _login() async { + Future _login() async { setState(() => _loading = true); //Try logging in String arl; diff --git a/lib/ui/settings_screen.dart b/lib/ui/settings_screen.dart index f648f65..41dec4d 100644 --- a/lib/ui/settings_screen.dart +++ b/lib/ui/settings_screen.dart @@ -5,6 +5,7 @@ import 'package:filesize/filesize.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_displaymode/flutter_displaymode.dart'; import 'package:flutter_material_color_picker/flutter_material_color_picker.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/web_symbols_icons.dart'; @@ -329,6 +330,32 @@ class _AppearanceSettingsState extends State { value: settings.useArtColor, onChanged: (v) => setState(() => settings.updateUseArtColor(v)), ), + ), + //Display mode + ListTile( + leading: Icon(Icons.screen_lock_portrait), + title: Text('Change display mode'.i18n), + subtitle: Text('Enable high refresh rates'.i18n), + onTap: () async { + List modes = await FlutterDisplayMode.supported; + showDialog( + context: context, + builder: (context) { + return SimpleDialog( + title: Text('Display mode'.i18n), + children: List.generate(modes.length, (i) => SimpleDialogOption( + child: Text(modes[i].toString()), + onPressed: () async { + settings.displayMode = i; + await settings.save(); + await FlutterDisplayMode.setMode(modes[i]); + Navigator.of(context).pop(); + }, + )) + ); + } + ); + }, ) ], ), diff --git a/pubspec.lock b/pubspec.lock index e6e543a..872cd8e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -351,6 +351,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.2" + flutter_displaymode: + dependency: "direct main" + description: + name: flutter_displaymode + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1" flutter_inappwebview: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index bdd1848..c8a8f20 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: flutter_localizations: sdk: flutter + flutter_displaymode: ^0.1.1 crypto: ^2.1.5 http: ^0.12.2 cookie_jar: ^1.0.1