Logout option

This commit is contained in:
exttex 2020-07-16 22:25:30 +02:00
parent abf355779c
commit 4b3d264e2a
6 changed files with 113 additions and 38 deletions

View file

@ -1,6 +1,7 @@
import 'package:custom_navigator/custom_navigator.dart';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:freezer/ui/library.dart';
import 'package:freezer/ui/login_screen.dart';
import 'package:freezer/ui/search.dart';
@ -14,7 +15,9 @@ import 'api/download.dart';
import 'api/player.dart';
import 'ui/home_screen.dart';
Function updateTheme;
Function logOut;
GlobalKey<NavigatorState> mainNavigatorKey = GlobalKey<NavigatorState>();
GlobalKey<NavigatorState> navigatorKey;
@ -90,9 +93,21 @@ class _LoginMainWrapperState extends State<LoginMainWrapper> {
if (b) setState(() => settings.offlineMode = false);
});
}
//Global logOut function
logOut = _logOut;
super.initState();
}
Future _logOut() async {
setState(() {
settings.arl = null;
settings.offlineMode = true;
deezerAPI = new DeezerAPI();
});
await settings.save();
}
@override
Widget build(BuildContext context) {
if (settings.arl == null)

View file

@ -141,6 +141,8 @@ class _CachedImageState extends State<CachedImage> {
//Load image and fade
void _load() async {
if (_prevUrl == widget.url) return;
ImageProvider image = await _getImage();
if (_disposed) return;
setState(() {
@ -164,7 +166,6 @@ class _CachedImageState extends State<CachedImage> {
@override
void didUpdateWidget(CachedImage oldWidget) {
if (_prevUrl == widget.url) return;
_load();
super.didUpdateWidget(oldWidget);
}
@ -183,6 +184,7 @@ class _CachedImageState extends State<CachedImage> {
height: widget.height,
width: widget.width,
),
AnimatedOpacity(
duration: Duration(milliseconds: 250),
opacity: _opacity,

View file

@ -11,14 +11,31 @@ import '../settings.dart';
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
//TODO: SingleChildScrollView vs ListView speed/perf
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: FreezerTitle(),
),
Flexible(child: HomePageScreen(),)
],
),
);
/*
return ListView(
children: <Widget>[
Container(height: 16.0,),
FreezerTitle(),
Container(height: 16.0,),
Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: FreezerTitle(),
),
HomePageScreen()
],
);
*/
}
}
@ -124,38 +141,40 @@ class _HomePageScreenState extends State<HomePageScreen> {
return Center(child: CircularProgressIndicator(),);
if (_error)
return ErrorScreen();
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: List.generate(_homePage.sections.length, (i) {
HomePageSection section = _homePage.sections[i];
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
child: Text(
section.title,
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 24.0),
),
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0)
return ListView.builder(
shrinkWrap: true,
addAutomaticKeepAlives: true,
physics: NeverScrollableScrollPhysics(),
itemCount: _homePage.sections.length,
itemBuilder: (context, i) {
HomePageSection section = _homePage.sections[i];
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
child: Text(
section.title,
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 24.0),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(section.items.length, (i) {
HomePageItem item = section.items[i];
return HomePageItemWidget(item);
}),
),
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0)
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(section.items.length, (i) {
HomePageItem item = section.items[i];
return HomePageItemWidget(item);
}),
),
],
);
}),
),
),
],
);
},
);
}
}
@ -168,6 +187,7 @@ class HomePageItemWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
switch (item.type) {
case HomePageItemType.SMARTTRACKLIST:
return SmartTrackListTile(

View file

@ -169,11 +169,11 @@ class _PlayerScreenState extends State<PlayerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(28, 16, 28, 0),
padding: EdgeInsets.fromLTRB(28, 12, 28, 4),
child: PlayerScreenTopRow()
),
Padding(
padding: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
child: Container(
height: 360,
child: Stack(
@ -229,7 +229,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
),
//Container(height: 8.0,),
Padding(
padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0),
padding: EdgeInsets.symmetric(vertical: 0, horizontal: 16.0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,

View file

@ -1,13 +1,14 @@
import 'package:audio_service/audio_service.dart';
import 'package:country_pickers/country.dart';
import 'package:country_pickers/country_picker_dialog.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:freezer/api/deezer.dart';
import 'package:freezer/ui/error.dart';
import 'package:freezer/ui/player_bar.dart';
import 'package:language_pickers/language_pickers.dart';
import 'package:language_pickers/languages.dart';
import 'package:package_info/package_info.dart';
@ -501,6 +502,42 @@ class _GeneralSettingsState extends State<GeneralSettings> {
settings.save();
},
),
),
ListTile(
title: Text('Log out', style: TextStyle(color: Colors.red),),
leading: Icon(Icons.exit_to_app),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Log out'),
content: Text('Due to plugin incompatibility, login using browser is unavailable without restart.'),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () => Navigator.of(context).pop(),
),
FlatButton(
child: Text('(ARL ONLY) Continue'),
onPressed: () {
logOut();
Navigator.of(context).pop();
},
),
FlatButton(
child: Text('Log out & Exit'),
onPressed: () async {
try {AudioService.stop();} catch (e) {}
await logOut();
SystemNavigator.pop();
},
)
],
);
}
);
}
)
],
),

View file

@ -239,6 +239,7 @@ class PlaylistCardTile extends StatelessWidget {
}
}
class SmartTrackListTile extends StatelessWidget {
final SmartTrackList smartTrackList;