Audio normalize

This commit is contained in:
LittleSheep 2024-08-29 22:34:56 +08:00
parent ef40c2ffe4
commit 586f47575c

View File

@ -2,8 +2,10 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:rhythm_box/providers/auth.dart'; import 'package:rhythm_box/providers/auth.dart';
import 'package:rhythm_box/providers/spotify.dart'; import 'package:rhythm_box/providers/spotify.dart';
import 'package:rhythm_box/providers/user_preferences.dart';
import 'package:rhythm_box/screens/auth/login.dart'; import 'package:rhythm_box/screens/auth/login.dart';
import 'package:rhythm_box/widgets/auto_cache_image.dart'; import 'package:rhythm_box/widgets/auto_cache_image.dart';
import 'package:rhythm_box/widgets/sized_container.dart';
class SettingsScreen extends StatefulWidget { class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key}); const SettingsScreen({super.key});
@ -15,6 +17,7 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> { class _SettingsScreenState extends State<SettingsScreen> {
late final SpotifyProvider _spotify = Get.find(); late final SpotifyProvider _spotify = Get.find();
late final AuthenticationProvider _authenticate = Get.find(); late final AuthenticationProvider _authenticate = Get.find();
late final UserPreferencesProvider _preferences = Get.find();
bool _isLoggingIn = false; bool _isLoggingIn = false;
@ -22,75 +25,94 @@ class _SettingsScreenState extends State<SettingsScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Material( return Material(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: SafeArea( child: Scaffold(
child: Column( appBar: AppBar(
children: [ title: const Text('Settings'),
Obx(() { centerTitle: MediaQuery.of(context).size.width >= 720,
if (_authenticate.auth.value == null) { ),
return ListTile( body: CenteredContainer(
contentPadding: const EdgeInsets.symmetric(horizontal: 24), child: Column(
leading: const Icon(Icons.login), children: [
title: const Text('Connect with Spotify'), Obx(() {
subtitle: const Text('To explore your own library and more'), if (_authenticate.auth.value == null) {
trailing: const Icon(Icons.chevron_right), return ListTile(
enabled: !_isLoggingIn, contentPadding: const EdgeInsets.symmetric(horizontal: 24),
onTap: () async { leading: const Icon(Icons.login),
setState(() => _isLoggingIn = true); title: const Text('Connect with Spotify'),
await universalLogin(context); subtitle:
setState(() => _isLoggingIn = false); const Text('To explore your own library and more'),
trailing: const Icon(Icons.chevron_right),
enabled: !_isLoggingIn,
onTap: () async {
setState(() => _isLoggingIn = true);
await universalLogin(context);
setState(() => _isLoggingIn = false);
},
);
}
return FutureBuilder(
future: _spotify.api.me.get(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 24),
leading: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 3,
),
),
title: Text('Loading...'),
);
}
return ListTile(
leading: (snapshot.data!.images?.isNotEmpty ?? false)
? CircleAvatar(
backgroundImage: AutoCacheImage.provider(
snapshot.data!.images!.firstOrNull!.url!,
),
)
: const Icon(Icons.account_circle),
title: Text(snapshot.data!.displayName!),
subtitle: const Text('Connected with your Spotify'),
);
}, },
); );
} }),
Obx(() {
if (_authenticate.auth.value == null) {
return const SizedBox();
}
return FutureBuilder( return ListTile(
future: _spotify.api.me.get(), contentPadding: const EdgeInsets.symmetric(horizontal: 24),
builder: (context, snapshot) { leading: const Icon(Icons.logout),
if (!snapshot.hasData) { title: const Text('Log out'),
return const ListTile( subtitle: const Text('Disconnect with this Spotify account'),
contentPadding: trailing: const Icon(Icons.chevron_right),
const EdgeInsets.symmetric(horizontal: 24), onTap: () async {
leading: SizedBox( _authenticate.logout();
width: 20, },
height: 20, );
child: CircularProgressIndicator( }),
strokeWidth: 3, const Divider(thickness: 0.3, height: 1),
), Obx(
), () => SwitchListTile(
title: Text('Loading...'), contentPadding: const EdgeInsets.symmetric(horizontal: 24),
); secondary: const Icon(Icons.graphic_eq),
} title: const Text('Normalize Audio'),
subtitle:
return ListTile( const Text('Make audio not too loud either too quiet'),
leading: (snapshot.data!.images?.isNotEmpty ?? false) value: _preferences.state.value.normalizeAudio,
? CircleAvatar( onChanged: _preferences.setNormalizeAudio,
backgroundImage: AutoCacheImage.provider( ),
snapshot.data!.images!.firstOrNull!.url!, ),
), ],
) ),
: const Icon(Icons.account_circle),
title: Text(snapshot.data!.displayName!),
subtitle: const Text('Connected with your Spotify'),
);
},
);
}),
Obx(() {
if (_authenticate.auth.value == null) {
return const SizedBox();
}
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: const Icon(Icons.logout),
title: const Text('Log out'),
subtitle: const Text('Disconnect with this Spotify account'),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
_authenticate.logout();
},
);
}),
],
), ),
), ),
); );