From 0357a4db6b24467b83b6455cc33ac53bf1530853 Mon Sep 17 00:00:00 2001 From: Adrian Baumgart Date: Sun, 9 Jul 2023 23:15:15 +0200 Subject: [PATCH] added logout feature --- lib/API/ServerManager.dart | 6 ++++++ lib/HomeView.dart | 20 +++++++++++++++++ lib/LoginView.dart | 44 ++++++++++++++++++++++++-------------- lib/ShortURLEditView.dart | 2 +- lib/URLDetailView.dart | 4 ++-- lib/main.dart | 2 +- 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/lib/API/ServerManager.dart b/lib/API/ServerManager.dart index e600594..ece6c7a 100644 --- a/lib/API/ServerManager.dart +++ b/lib/API/ServerManager.dart @@ -27,6 +27,12 @@ class ServerManager { return (_server_url != null); } + Future logOut() async { + const storage = FlutterSecureStorage(); + await storage.delete(key: "shlink_url"); + await storage.delete(key: "shlink_apikey"); + } + Future _loadCredentials() async { const storage = FlutterSecureStorage(); _server_url = await storage.read(key: "shlink_url"); diff --git a/lib/HomeView.dart b/lib/HomeView.dart index 0fa3f02..6c52fe6 100644 --- a/lib/HomeView.dart +++ b/lib/HomeView.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:shlink_app/API/Classes/ShlinkStats/ShlinkStats.dart'; import 'package:shlink_app/API/ServerManager.dart'; +import 'package:shlink_app/LoginView.dart'; import 'package:shlink_app/ShortURLEditView.dart'; import 'globals.dart' as globals; @@ -57,6 +58,25 @@ class _HomeViewState extends State { Text(globals.serverManager.getServerUrl(), style: TextStyle(fontSize: 16, color: Colors.grey[600])) ], ), + actions: [ + PopupMenuButton( + itemBuilder: (context) { + return [ + PopupMenuItem( + value: 0, + child: Text("Log out...", style: TextStyle(color: Colors.red)), + ) + ]; + }, + onSelected: (value) { + if (value == 0) { + globals.serverManager.logOut().then((value) => Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (context) => const LoginView()) + )); + } + }, + ) + ], ), SliverToBoxAdapter( child: Wrap( diff --git a/lib/LoginView.dart b/lib/LoginView.dart index 37fec48..8299ed9 100644 --- a/lib/LoginView.dart +++ b/lib/LoginView.dart @@ -62,7 +62,7 @@ class _LoginViewState extends State { body: CustomScrollView( slivers: [ SliverAppBar.medium( - title: const Text("Add server") + title: const Text("Add server", style: TextStyle(fontWeight: FontWeight.bold)) ), SliverFillRemaining( child: Padding( @@ -73,26 +73,38 @@ class _LoginViewState extends State { children: [ const Padding(padding: EdgeInsets.only(bottom: 8), child: Text("Server URL", style: TextStyle(fontWeight: FontWeight.bold),)), - TextField( - controller: _server_url_controller, - keyboardType: TextInputType.url, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "https://shlink.example.com" - ), + Row( + children: [ + Icon(Icons.dns_outlined), + SizedBox(width: 8), + Expanded(child: TextField( + controller: _server_url_controller, + keyboardType: TextInputType.url, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "https://shlink.example.com" + ), + )) + ], ), const Padding( padding: EdgeInsets.only(top: 8, bottom: 8), child: Text("API Key", style: TextStyle(fontWeight: FontWeight.bold)), ), - TextField( - controller: _apikey_controller, - keyboardType: TextInputType.text, - obscureText: true, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "..." - ), + Row( + children: [ + Icon(Icons.key), + SizedBox(width: 8), + Expanded(child: TextField( + controller: _apikey_controller, + keyboardType: TextInputType.text, + obscureText: true, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "..." + ), + )) + ], ), Padding( padding: const EdgeInsets.only(top: 16), diff --git a/lib/ShortURLEditView.dart b/lib/ShortURLEditView.dart index 1e06cfd..ddc4f9d 100644 --- a/lib/ShortURLEditView.dart +++ b/lib/ShortURLEditView.dart @@ -169,7 +169,7 @@ class _ShortURLEditViewState extends State with SingleTickerPr }); }, - icon: Icon(randomSlug ? Icons.casino : Icons.casino_outlined, color: randomSlug ? Colors.green : Theme.of(context).primaryColor,) + icon: Icon(randomSlug ? Icons.casino : Icons.casino_outlined, color: randomSlug ? Colors.green : Colors.grey) ), ) ], diff --git a/lib/URLDetailView.dart b/lib/URLDetailView.dart index 17a2c90..3f6af98 100644 --- a/lib/URLDetailView.dart +++ b/lib/URLDetailView.dart @@ -160,7 +160,7 @@ class _ListCellState extends State<_ListCell> { padding: EdgeInsets.only(right: 4), child: SizedBox( width: 20, - height: 8, + height: 6, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), @@ -182,7 +182,7 @@ class _ListCellState extends State<_ListCell> { else if (widget.content is DateTime) Text(DateFormat('yyyy-MM-dd - HH:mm').format(widget.content)) else - Text("N/A") + const Text("N/A") ], ), ), diff --git a/lib/main.dart b/lib/main.dart index c48f786..aa381d0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -37,7 +37,7 @@ class MyApp extends StatelessWidget { foregroundColor: Colors.white, elevation: 0, ), - colorScheme: darkColorScheme?.copyWith(background: Colors.black, primary: Colors.blue) ?? _defaultDarkColorScheme, + colorScheme: darkColorScheme?.copyWith(background: Colors.black) ?? _defaultDarkColorScheme, useMaterial3: true, ), /*theme: ThemeData(