From 350fc75803cd1169d316a50f1afd3d85ae995384 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Wed, 2 Feb 2022 13:27:23 +0600 Subject: [PATCH] non matching drop down background fix option to add genius access_token on Login Screen red logout button --- lib/components/Login.dart | 149 +++++++++++++++++++++-------------- lib/components/Settings.dart | 3 + lib/main.dart | 1 + 3 files changed, 93 insertions(+), 60 deletions(-) diff --git a/lib/components/Login.dart b/lib/components/Login.dart index aad4cc44..e7bb4427 100644 --- a/lib/components/Login.dart +++ b/lib/components/Login.dart @@ -1,8 +1,12 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:spotube/components/Shared/Hyperlink.dart'; import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; import 'package:spotube/helpers/oauth-login.dart'; +import 'package:spotube/models/LocalStorageKeys.dart'; import 'package:spotube/provider/Auth.dart'; +import 'package:spotube/provider/UserPreferences.dart'; class Login extends StatefulWidget { const Login({Key? key}) : super(key: key); @@ -14,9 +18,10 @@ class Login extends StatefulWidget { class _LoginState extends State { String clientId = ""; String clientSecret = ""; + String accessToken = ""; bool _fieldError = false; - handleLogin(Auth authState) async { + Future handleLogin(Auth authState) async { try { if (clientId == "" || clientSecret == "") { return setState(() { @@ -35,67 +40,91 @@ class _LoginState extends State { builder: (context, authState, child) { return Scaffold( appBar: const PageWindowTitleBar(), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Image.asset( - "assets/spotube-logo.png", - width: 400, - height: 400, - ), - Text("Add your spotify credentials to get started", - style: Theme.of(context).textTheme.headline4), - const Text( - "Don't worry, any of your credentials won't be collected or shared with anyone"), - const SizedBox( - height: 10, - ), - Container( - constraints: const BoxConstraints( - maxWidth: 400, + body: SingleChildScrollView( + child: Center( + child: Column( + children: [ + Image.asset( + "assets/spotube-logo.png", + width: 400, + height: 400, ), - child: Column( - children: [ - TextField( - decoration: const InputDecoration( - hintText: "Spotify Client ID", - label: Text("ClientID"), - ), - onChanged: (value) { - setState(() { - clientId = value; - }); - }, - ), - const SizedBox( - height: 10, - ), - TextField( - decoration: const InputDecoration( - hintText: "Spotify Client Secret", - label: Text("Client Secret"), - ), - onChanged: (value) { - setState(() { - clientSecret = value; - }); - }, - ), - const SizedBox( - height: 10, - ), - ElevatedButton( - onPressed: () { - handleLogin(authState); - }, - child: const Text("Submit"), - ) - ], + Text("Add your spotify credentials to get started", + style: Theme.of(context).textTheme.headline4), + const Text( + "Don't worry, any of your credentials won't be collected or shared with anyone"), + const Hyperlink("How to get these client-id & client-secret?", + "https://github.com/KRTirtho/spotube#configuration"), + const SizedBox( + height: 10, ), - ), - ], + Container( + constraints: const BoxConstraints( + maxWidth: 400, + ), + child: Column( + children: [ + TextField( + decoration: const InputDecoration( + hintText: "Spotify Client ID", + label: Text("ClientID"), + ), + onChanged: (value) { + setState(() { + clientId = value; + }); + }, + ), + const SizedBox(height: 10), + TextField( + decoration: const InputDecoration( + hintText: "Spotify Client Secret", + label: Text("Client Secret"), + ), + onChanged: (value) { + setState(() { + clientSecret = value; + }); + }, + ), + const SizedBox(height: 10), + const Divider(color: Colors.grey), + const SizedBox(height: 10), + TextField( + decoration: const InputDecoration( + label: Text("Genius Access Token (optional)"), + ), + onChanged: (value) { + setState(() { + accessToken = value; + }); + }, + ), + const SizedBox( + height: 10, + ), + ElevatedButton( + onPressed: () async { + await handleLogin(authState); + UserPreferences preferences = + context.read(); + SharedPreferences localStorage = + await SharedPreferences.getInstance(); + preferences.setGeniusAccessToken(accessToken); + await localStorage.setString( + LocalStorageKeys.geniusAccessToken, + accessToken); + setState(() { + accessToken = ""; + }); + }, + child: const Text("Submit"), + ) + ], + ), + ), + ], + ), ), ), ); diff --git a/lib/components/Settings.dart b/lib/components/Settings.dart index e3c70693..ee8c48de 100644 --- a/lib/components/Settings.dart +++ b/lib/components/Settings.dart @@ -135,6 +135,9 @@ class _SettingsState extends State { const Text("Log out of this account"), ElevatedButton( child: const Text("Logout"), + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(Colors.red), + ), onPressed: () async { SharedPreferences localStorage = await SharedPreferences.getInstance(); diff --git a/lib/main.dart b/lib/main.dart index 0acc5769..f1bb3faa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -200,6 +200,7 @@ class _MyAppState extends State { color: Colors.blueGrey[900], elevation: 20, ), + canvasColor: Colors.blueGrey[900], ), themeMode: _themeMode, home: const Home(),