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;
final List<OnlinePodcast> _podcastList = [];
Future _searchTopPodcast;
Future _getIfHideDiscovery;
Future<List<String>> _getSearchHistory() {
final storage = KeyValueStorage(searchHistoryKey);
final history = storage.getStringList();
@ -40,6 +41,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
void initState() {
super.initState();
_searchTopPodcast = _getTopPodcasts(page: 1);
_getIfHideDiscovery = _getHideDiscovery();
}
Widget _loadTopPodcasts() => Container(
@ -126,8 +128,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
.map<Widget>((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<DiscoveryPage> {
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<DiscoveryPage> {
@override
Widget build(BuildContext context) {
final searchState = context.watch<SearchState>();
return FutureBuilder<bool>(
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<DiscoveryPage> {
],
),
),
)
: PodcastSlideup(
);
} else {
return PodcastSlideup(
searchEngine: SearchEngine.listenNotes,
child: Selector<SearchState, Genre>(
selector: (_, searchState) => searchState.genre,
@ -289,7 +292,7 @@ class DiscoveryPageState extends State<DiscoveryPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_historyList(),
SizedBox(height: 8),
SizedBox(height: 8),
SizedBox(
height: 200,
child: FutureBuilder<List<OnlinePodcast>>(
@ -306,7 +309,8 @@ class DiscoveryPageState extends State<DiscoveryPage> {
return _podcastCard(
podcast,
onTap: () {
searchState
context
.read<SearchState>()
.selectedPodcast =
podcast;
widget.onTap('');
@ -337,9 +341,11 @@ class DiscoveryPageState extends State<DiscoveryPage> {
EdgeInsets.fromLTRB(20, 0, 20, 0),
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(),
),
@ -362,8 +368,9 @@ class DiscoveryPageState extends State<DiscoveryPage> {
],
),
),
),
);
);
}
});
}
}

View File

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

View File

@ -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) {

View File

@ -81,7 +81,6 @@ Future<T> showSearch<T>({
/// call. Call [SearchDelegate.close] before re-using the same delegate instance
/// for another [showSearch] call.
abstract class SearchDelegate<T> {
/// Constructor to be called by subclasses which may specify [searchFieldLabel], [keyboardType] and/or
/// [textInputAction].
///
@ -236,7 +235,8 @@ abstract class SearchDelegate<T> {
///
/// * [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<T> {
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<T> extends State<_SearchPage<T>> {
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<T> extends State<_SearchPage<T>> {
}
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<T> extends State<_SearchPage<T>> {
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<T> extends State<_SearchPage<T>> {
),
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,
// ),
),
);
}
}
}