diff --git a/lib/home/pocast_discovery.dart b/lib/home/pocast_discovery.dart index f91dc5f..14467b3 100644 --- a/lib/home/pocast_discovery.dart +++ b/lib/home/pocast_discovery.dart @@ -24,6 +24,7 @@ class DiscoveryPageState extends State { Genre get selectedGenre => _selectedGenre; final List _podcastList = []; Future _searchTopPodcast; + Future _getIfHideDiscovery; Future> _getSearchHistory() { final storage = KeyValueStorage(searchHistoryKey); final history = storage.getStringList(); @@ -40,6 +41,7 @@ class DiscoveryPageState extends State { void initState() { super.initState(); _searchTopPodcast = _getTopPodcasts(page: 1); + _getIfHideDiscovery = _getHideDiscovery(); } Widget _loadTopPodcasts() => Container( @@ -126,8 +128,7 @@ class DiscoveryPageState extends State { .map((e) => Padding( padding: const EdgeInsets.fromLTRB(8, 2, 0, 0), child: FlatButton.icon( - color: - Colors.accents[history.indexOf(e)].withAlpha(70), + color: Colors.accents[history.indexOf(e)].withAlpha(70), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(100.0), ), @@ -150,9 +151,10 @@ class DiscoveryPageState extends State { Widget _podcastCard(OnlinePodcast podcast, {VoidCallback onTap}) { return Container( decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), color: context.primaryColor, - border: Border.all(color: context.textColor.withOpacity(0.1), width: 1) - ), + borderRadius: BorderRadius.circular(10), + color: context.primaryColor, + border: + Border.all(color: context.textColor.withOpacity(0.1), width: 1)), width: 120, margin: EdgeInsets.fromLTRB(10, 10, 0, 10), child: Material( @@ -213,13 +215,13 @@ class DiscoveryPageState extends State { @override Widget build(BuildContext context) { - final searchState = context.watch(); return FutureBuilder( - future: _getHideDiscovery(), - initialData: true, - builder: (context, snapshot) => snapshot.data || - environment['apiKey'] == '' - ? ScrollConfiguration( + future: _getIfHideDiscovery, + builder: (context, snapshot) { + if (!snapshot.hasData) { + return Center(); + } else if (snapshot.data || environment['apiKey'] == '') { + return ScrollConfiguration( behavior: NoGrowBehavior(), child: SingleChildScrollView( child: Column( @@ -275,8 +277,9 @@ class DiscoveryPageState extends State { ], ), ), - ) - : PodcastSlideup( + ); + } else { + return PodcastSlideup( searchEngine: SearchEngine.listenNotes, child: Selector( selector: (_, searchState) => searchState.genre, @@ -289,7 +292,7 @@ class DiscoveryPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ _historyList(), - SizedBox(height: 8), + SizedBox(height: 8), SizedBox( height: 200, child: FutureBuilder>( @@ -306,7 +309,8 @@ class DiscoveryPageState extends State { return _podcastCard( podcast, onTap: () { - searchState + context + .read() .selectedPodcast = podcast; widget.onTap(''); @@ -337,9 +341,11 @@ class DiscoveryPageState extends State { EdgeInsets.fromLTRB(20, 0, 20, 0), onTap: () { widget.onTap(''); - searchState.setGenre = e; + context.read().setGenre = + e; }, - title: Text(e.name, style: context.textTheme.headline6), + title: Text(e.name, + style: context.textTheme.headline6), )) .toList(), ), @@ -362,8 +368,9 @@ class DiscoveryPageState extends State { ], ), ), - ), - ); + ); + } + }); } } diff --git a/lib/podcasts/podcast_group.dart b/lib/podcasts/podcast_group.dart index 3b08291..3666765 100644 --- a/lib/podcasts/podcast_group.dart +++ b/lib/podcasts/podcast_group.dart @@ -77,7 +77,6 @@ class _PodcastCard extends StatefulWidget { class __PodcastCardState extends State<_PodcastCard> with SingleTickerProviderStateMixin { - bool _loadMenu; bool _addGroup; List _selectedGroups; List _belongGroups; @@ -129,7 +128,6 @@ class __PodcastCardState extends State<_PodcastCard> @override void initState() { super.initState(); - _loadMenu = false; _addGroup = false; _selectedGroups = [widget.group]; _value = 0; diff --git a/lib/state/download_state.dart b/lib/state/download_state.dart index f7f41d1..736821d 100644 --- a/lib/state/download_state.dart +++ b/lib/state/download_state.dart @@ -161,7 +161,6 @@ class DownloadState extends ChangeNotifier { taskId: task.taskId, shouldDeleteContent: true); } else { if (task.status == DownloadTaskStatus.complete) { - final filname = task.filename.replaceAll('/', ''); var exist = await File(path.join(task.savedDir, task.filename)).exists(); if (!exist) { diff --git a/lib/widgets/custom_search_delegate.dart b/lib/widgets/custom_search_delegate.dart index c7962a1..33aabd5 100644 --- a/lib/widgets/custom_search_delegate.dart +++ b/lib/widgets/custom_search_delegate.dart @@ -81,7 +81,6 @@ Future showSearch({ /// call. Call [SearchDelegate.close] before re-using the same delegate instance /// for another [showSearch] call. abstract class SearchDelegate { - /// Constructor to be called by subclasses which may specify [searchFieldLabel], [keyboardType] and/or /// [textInputAction]. /// @@ -236,7 +235,8 @@ abstract class SearchDelegate { /// /// * [showResults] to show the search results. void showSuggestions(BuildContext context) { - assert(_focusNode != null, '_focusNode must be set by route before showSuggestions is called.'); + assert(_focusNode != null, + '_focusNode must be set by route before showSuggestions is called.'); _focusNode.requestFocus(); _currentBody = _SearchBody.suggestions; } @@ -290,9 +290,11 @@ abstract class SearchDelegate { final TextEditingController _queryTextController = TextEditingController(); - final ProxyAnimation _proxyAnimation = ProxyAnimation(kAlwaysDismissedAnimation); + final ProxyAnimation _proxyAnimation = + ProxyAnimation(kAlwaysDismissedAnimation); - final ValueNotifier<_SearchBody> _currentBodyNotifier = ValueNotifier<_SearchBody>(null); + final ValueNotifier<_SearchBody> _currentBodyNotifier = + ValueNotifier<_SearchBody>(null); _SearchBody get _currentBody => _currentBodyNotifier.value; set _currentBody(_SearchBody value) { @@ -438,7 +440,8 @@ class _SearchPageState extends State<_SearchPage> { if (widget.delegate != oldWidget.delegate) { oldWidget.delegate._queryTextController.removeListener(_onQueryChanged); widget.delegate._queryTextController.addListener(_onQueryChanged); - oldWidget.delegate._currentBodyNotifier.removeListener(_onSearchBodyChanged); + oldWidget.delegate._currentBodyNotifier + .removeListener(_onSearchBodyChanged); widget.delegate._currentBodyNotifier.addListener(_onSearchBodyChanged); oldWidget.delegate._focusNode = null; widget.delegate._focusNode = focusNode; @@ -446,7 +449,8 @@ class _SearchPageState extends State<_SearchPage> { } void _onFocusChanged() { - if (focusNode.hasFocus && widget.delegate._currentBody != _SearchBody.suggestions) { + if (focusNode.hasFocus && + widget.delegate._currentBody != _SearchBody.suggestions) { widget.delegate.showSuggestions(context); } } @@ -467,23 +471,17 @@ class _SearchPageState extends State<_SearchPage> { Widget build(BuildContext context) { assert(debugCheckHasMaterialLocalizations(context)); final ThemeData theme = widget.delegate.appBarTheme(context); - final String searchFieldLabel = widget.delegate.searchFieldLabel - ?? MaterialLocalizations.of(context).searchFieldLabel; - final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle - ?? theme.inputDecorationTheme.hintStyle; - Widget body; - switch(widget.delegate._currentBody) { + final String searchFieldLabel = widget.delegate.searchFieldLabel ?? + MaterialLocalizations.of(context).searchFieldLabel; + final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle ?? + theme.inputDecorationTheme.hintStyle; + int index; + switch (widget.delegate._currentBody) { case _SearchBody.suggestions: - body = KeyedSubtree( - key: const ValueKey<_SearchBody>(_SearchBody.suggestions), - child: widget.delegate.buildSuggestions(context), - ); + index = 0; break; case _SearchBody.results: - body = KeyedSubtree( - key: const ValueKey<_SearchBody>(_SearchBody.results), - child: widget.delegate.buildResults(context), - ); + index = 1; break; } String routeName; @@ -529,11 +527,24 @@ class _SearchPageState extends State<_SearchPage> { ), actions: widget.delegate.buildActions(context), ), - body: AnimatedSwitcher( - duration: const Duration(milliseconds: 300), - child: body, + body: IndexedStack( + index: index, + children: [ + KeyedSubtree( + key: const ValueKey<_SearchBody>(_SearchBody.suggestions), + child: widget.delegate.buildSuggestions(context), + ), + KeyedSubtree( + key: const ValueKey<_SearchBody>(_SearchBody.results), + child: widget.delegate.buildResults(context), + ) + ], ), + // AnimatedSwitcher( + // duration: const Duration(milliseconds: 300), + // child: body, + // ), ), ); } -} \ No newline at end of file +}