Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search input onChanged event #1459

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pages/desktop_login/desktop_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ class DesktopLoginPage extends HookConsumerWidget {
),
);
}
}
}
31 changes: 27 additions & 4 deletions lib/pages/mobile_login/mobile_login.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -6,6 +7,9 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:spotube/provider/authentication_provider.dart';
import 'package:spotube/utils/platform.dart';

const _userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";

class WebViewLogin extends HookConsumerWidget {
const WebViewLogin({super.key});

Expand All @@ -14,7 +18,7 @@ class WebViewLogin extends HookConsumerWidget {
final authenticationNotifier = ref.watch(authenticationProvider.notifier);

if (kIsDesktop) {
const Scaffold(
return const Scaffold(
body: Center(
child: Text('This feature is not available on desktop'),
),
Expand All @@ -24,9 +28,16 @@ class WebViewLogin extends HookConsumerWidget {
return Scaffold(
body: SafeArea(
child: InAppWebView(
master
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: _userAgent,
),

initialSettings: InAppWebViewSettings(
userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 afari/537.36",
master
),
initialUrlRequest: URLRequest(
url: WebUri("https://accounts.spotify.com/"),
Expand All @@ -49,20 +60,32 @@ class WebViewLogin extends HookConsumerWidget {
if (exp.hasMatch(url)) {
final cookies =
await CookieManager.instance().getCookies(url: action);
final cookieHeader =
"sp_dc=${cookies.firstWhere((element) => element.name == "sp_dc").value}";
final spDcCookie = cookies.firstWhereOrNull((element) => element.name == "sp_dc");

if (spDcCookie != null) {
final cookieHeader = "sp_dc=${spDcCookie.value}";

master
authenticationNotifier.setCredentials(
await AuthenticationCredentials.fromCookie(cookieHeader),
);
if (mounted()) {
// ignore: use_build_context_synchronously
GoRouter.of(context).pushReplacementNamed("/");
}

authenticationNotifier.setCredentials(
await AuthenticationCredentials.fromCookie(cookieHeader),
);
if (context.mounted) {
// ignore: use_build_context_synchronously
GoRouter.of(context).go("/");
master
}
}
},
),
),
);
}
}
}
19 changes: 19 additions & 0 deletions lib/pages/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ class SearchPage extends HookConsumerWidget {
vertical: 10,
),
color: theme.scaffoldBackgroundColor,
master
child: TextField(
autofocus: queries
.none((s) => s.hasPageData && !s.hasPageError) &&
!kIsMobile,
decoration: InputDecoration(
prefixIcon: const Icon(SpotubeIcons.search),
hintText: "${context.l10n.search}...",
),
onChanged: (value) async {
ref.read(searchTermStateProvider.notifier).state =
value;
// Fl-Query is too fast, so we need to delay the search
// to prevent spamming the API :)
Timer(const Duration(milliseconds: 50), () {
onSearch();
});

child: SearchAnchor(
searchController: controller,
viewBuilder: (_) => HookBuilder(builder: (context) {
Expand Down Expand Up @@ -176,6 +194,7 @@ class SearchPage extends HookConsumerWidget {
onTap: controller.openView,
onChanged: (_) => controller.openView(),
);
master
},
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/authentication_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ class AuthenticationNotifier
final authenticationProvider =
StateNotifierProvider<AuthenticationNotifier, AuthenticationCredentials?>(
(ref) => AuthenticationNotifier(),
);
);
22 changes: 11 additions & 11 deletions lib/themes/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
surface: isAmoled ? Colors.black : null,
brightness: brightness,
);

const borderRadius = BorderRadius.all(Radius.circular(15));
const roundedRectangleBorder = RoundedRectangleBorder(borderRadius: borderRadius);

return ThemeData(
useMaterial3: true,
colorScheme: scheme,
Expand All @@ -16,9 +20,9 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
iconColor: scheme.onSurface,
),
appBarTheme: const AppBarTheme(surfaceTintColor: Colors.transparent),
inputDecorationTheme: InputDecorationTheme(
inputDecorationTheme: const InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderRadius: borderRadius,
),
),
iconTheme: IconThemeData(size: 16, color: scheme.onSurface),
Expand All @@ -36,17 +40,17 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
dividerColor: Colors.transparent,
indicator: BoxDecoration(
color: scheme.secondaryContainer,
borderRadius: BorderRadius.circular(15),
borderRadius: borderRadius,
),
),
popupMenuTheme: PopupMenuThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
shape: roundedRectangleBorder,
color: scheme.surface,
elevation: 4,
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
shape: roundedRectangleBorder,
backgroundColor: scheme.onSurface,
contentTextStyle: TextStyle(color: scheme.surface),
),
Expand All @@ -63,11 +67,7 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
),
),
elevation: const MaterialStatePropertyAll(0),
shape: MaterialStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
shape: MaterialStatePropertyAll(roundedRectangleBorder),
),
scrollbarTheme: const ScrollbarThemeData(
thickness: MaterialStatePropertyAll(14),
Expand All @@ -76,4 +76,4 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
),
);
}
}