Minor change.

This commit is contained in:
Stonegate 2021-02-10 00:40:24 +08:00
parent 35b1e5c372
commit 5ef238df32
4 changed files with 61 additions and 46 deletions

View File

@ -24,6 +24,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
Genre get selectedGenre => _selectedGenre; Genre get selectedGenre => _selectedGenre;
final List<OnlinePodcast> _podcastList = []; final List<OnlinePodcast> _podcastList = [];
Future _searchTopPodcast; Future _searchTopPodcast;
Future _getIfHideDiscovery;
Future<List<String>> _getSearchHistory() { Future<List<String>> _getSearchHistory() {
final storage = KeyValueStorage(searchHistoryKey); final storage = KeyValueStorage(searchHistoryKey);
final history = storage.getStringList(); final history = storage.getStringList();
@ -40,6 +41,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
void initState() { void initState() {
super.initState(); super.initState();
_searchTopPodcast = _getTopPodcasts(page: 1); _searchTopPodcast = _getTopPodcasts(page: 1);
_getIfHideDiscovery = _getHideDiscovery();
} }
Widget _loadTopPodcasts() => Container( Widget _loadTopPodcasts() => Container(
@ -126,8 +128,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
.map<Widget>((e) => Padding( .map<Widget>((e) => Padding(
padding: const EdgeInsets.fromLTRB(8, 2, 0, 0), padding: const EdgeInsets.fromLTRB(8, 2, 0, 0),
child: FlatButton.icon( child: FlatButton.icon(
color: color: Colors.accents[history.indexOf(e)].withAlpha(70),
Colors.accents[history.indexOf(e)].withAlpha(70),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0), borderRadius: BorderRadius.circular(100.0),
), ),
@ -150,9 +151,10 @@ class DiscoveryPageState extends State<DiscoveryPage> {
Widget _podcastCard(OnlinePodcast podcast, {VoidCallback onTap}) { Widget _podcastCard(OnlinePodcast podcast, {VoidCallback onTap}) {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: context.primaryColor, borderRadius: BorderRadius.circular(10),
border: Border.all(color: context.textColor.withOpacity(0.1), width: 1) color: context.primaryColor,
), border:
Border.all(color: context.textColor.withOpacity(0.1), width: 1)),
width: 120, width: 120,
margin: EdgeInsets.fromLTRB(10, 10, 0, 10), margin: EdgeInsets.fromLTRB(10, 10, 0, 10),
child: Material( child: Material(
@ -213,13 +215,13 @@ class DiscoveryPageState extends State<DiscoveryPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final searchState = context.watch<SearchState>();
return FutureBuilder<bool>( return FutureBuilder<bool>(
future: _getHideDiscovery(), future: _getIfHideDiscovery,
initialData: true, builder: (context, snapshot) {
builder: (context, snapshot) => snapshot.data || if (!snapshot.hasData) {
environment['apiKey'] == '' return Center();
? ScrollConfiguration( } else if (snapshot.data || environment['apiKey'] == '') {
return ScrollConfiguration(
behavior: NoGrowBehavior(), behavior: NoGrowBehavior(),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
@ -275,8 +277,9 @@ class DiscoveryPageState extends State<DiscoveryPage> {
], ],
), ),
), ),
) );
: PodcastSlideup( } else {
return PodcastSlideup(
searchEngine: SearchEngine.listenNotes, searchEngine: SearchEngine.listenNotes,
child: Selector<SearchState, Genre>( child: Selector<SearchState, Genre>(
selector: (_, searchState) => searchState.genre, selector: (_, searchState) => searchState.genre,
@ -306,7 +309,8 @@ class DiscoveryPageState extends State<DiscoveryPage> {
return _podcastCard( return _podcastCard(
podcast, podcast,
onTap: () { onTap: () {
searchState context
.read<SearchState>()
.selectedPodcast = .selectedPodcast =
podcast; podcast;
widget.onTap(''); widget.onTap('');
@ -337,9 +341,11 @@ class DiscoveryPageState extends State<DiscoveryPage> {
EdgeInsets.fromLTRB(20, 0, 20, 0), EdgeInsets.fromLTRB(20, 0, 20, 0),
onTap: () { onTap: () {
widget.onTap(''); widget.onTap('');
searchState.setGenre = e; context.read<SearchState>().setGenre =
e;
}, },
title: Text(e.name, style: context.textTheme.headline6), title: Text(e.name,
style: context.textTheme.headline6),
)) ))
.toList(), .toList(),
), ),
@ -362,8 +368,9 @@ class DiscoveryPageState extends State<DiscoveryPage> {
], ],
), ),
), ),
), );
); }
});
} }
} }

View File

@ -77,7 +77,6 @@ class _PodcastCard extends StatefulWidget {
class __PodcastCardState extends State<_PodcastCard> class __PodcastCardState extends State<_PodcastCard>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
bool _loadMenu;
bool _addGroup; bool _addGroup;
List<PodcastGroup> _selectedGroups; List<PodcastGroup> _selectedGroups;
List<PodcastGroup> _belongGroups; List<PodcastGroup> _belongGroups;
@ -129,7 +128,6 @@ class __PodcastCardState extends State<_PodcastCard>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_loadMenu = false;
_addGroup = false; _addGroup = false;
_selectedGroups = [widget.group]; _selectedGroups = [widget.group];
_value = 0; _value = 0;

View File

@ -161,7 +161,6 @@ class DownloadState extends ChangeNotifier {
taskId: task.taskId, shouldDeleteContent: true); taskId: task.taskId, shouldDeleteContent: true);
} else { } else {
if (task.status == DownloadTaskStatus.complete) { if (task.status == DownloadTaskStatus.complete) {
final filname = task.filename.replaceAll('/', '');
var exist = var exist =
await File(path.join(task.savedDir, task.filename)).exists(); await File(path.join(task.savedDir, task.filename)).exists();
if (!exist) { if (!exist) {

View File

@ -81,7 +81,6 @@ Future<T> showSearch<T>({
/// call. Call [SearchDelegate.close] before re-using the same delegate instance /// call. Call [SearchDelegate.close] before re-using the same delegate instance
/// for another [showSearch] call. /// for another [showSearch] call.
abstract class SearchDelegate<T> { abstract class SearchDelegate<T> {
/// Constructor to be called by subclasses which may specify [searchFieldLabel], [keyboardType] and/or /// Constructor to be called by subclasses which may specify [searchFieldLabel], [keyboardType] and/or
/// [textInputAction]. /// [textInputAction].
/// ///
@ -236,7 +235,8 @@ abstract class SearchDelegate<T> {
/// ///
/// * [showResults] to show the search results. /// * [showResults] to show the search results.
void showSuggestions(BuildContext context) { 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(); _focusNode.requestFocus();
_currentBody = _SearchBody.suggestions; _currentBody = _SearchBody.suggestions;
} }
@ -290,9 +290,11 @@ abstract class SearchDelegate<T> {
final TextEditingController _queryTextController = TextEditingController(); 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; _SearchBody get _currentBody => _currentBodyNotifier.value;
set _currentBody(_SearchBody value) { set _currentBody(_SearchBody value) {
@ -438,7 +440,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
if (widget.delegate != oldWidget.delegate) { if (widget.delegate != oldWidget.delegate) {
oldWidget.delegate._queryTextController.removeListener(_onQueryChanged); oldWidget.delegate._queryTextController.removeListener(_onQueryChanged);
widget.delegate._queryTextController.addListener(_onQueryChanged); widget.delegate._queryTextController.addListener(_onQueryChanged);
oldWidget.delegate._currentBodyNotifier.removeListener(_onSearchBodyChanged); oldWidget.delegate._currentBodyNotifier
.removeListener(_onSearchBodyChanged);
widget.delegate._currentBodyNotifier.addListener(_onSearchBodyChanged); widget.delegate._currentBodyNotifier.addListener(_onSearchBodyChanged);
oldWidget.delegate._focusNode = null; oldWidget.delegate._focusNode = null;
widget.delegate._focusNode = focusNode; widget.delegate._focusNode = focusNode;
@ -446,7 +449,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
} }
void _onFocusChanged() { void _onFocusChanged() {
if (focusNode.hasFocus && widget.delegate._currentBody != _SearchBody.suggestions) { if (focusNode.hasFocus &&
widget.delegate._currentBody != _SearchBody.suggestions) {
widget.delegate.showSuggestions(context); widget.delegate.showSuggestions(context);
} }
} }
@ -467,23 +471,17 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = widget.delegate.appBarTheme(context); final ThemeData theme = widget.delegate.appBarTheme(context);
final String searchFieldLabel = widget.delegate.searchFieldLabel final String searchFieldLabel = widget.delegate.searchFieldLabel ??
?? MaterialLocalizations.of(context).searchFieldLabel; MaterialLocalizations.of(context).searchFieldLabel;
final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle ??
?? theme.inputDecorationTheme.hintStyle; theme.inputDecorationTheme.hintStyle;
Widget body; int index;
switch(widget.delegate._currentBody) { switch (widget.delegate._currentBody) {
case _SearchBody.suggestions: case _SearchBody.suggestions:
body = KeyedSubtree( index = 0;
key: const ValueKey<_SearchBody>(_SearchBody.suggestions),
child: widget.delegate.buildSuggestions(context),
);
break; break;
case _SearchBody.results: case _SearchBody.results:
body = KeyedSubtree( index = 1;
key: const ValueKey<_SearchBody>(_SearchBody.results),
child: widget.delegate.buildResults(context),
);
break; break;
} }
String routeName; String routeName;
@ -529,10 +527,23 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
), ),
actions: widget.delegate.buildActions(context), actions: widget.delegate.buildActions(context),
), ),
body: AnimatedSwitcher( body: IndexedStack(
duration: const Duration(milliseconds: 300), index: index,
child: body, 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,
// ),
), ),
); );
} }