Redesign player widget.

This commit is contained in:
stonegate 2020-07-29 20:06:49 +08:00
parent 1642c4b839
commit 814628ce3d
7 changed files with 1420 additions and 1688 deletions

View File

@ -2,20 +2,21 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:tuple/tuple.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';
import '../home/audioplayer.dart';
import '../local_storage/sqflite_localpodcast.dart';
import '../state/audio_state.dart';
import '../type/episodebrief.dart';
import '../type/play_histroy.dart';
import '../util/audiopanel.dart';
import '../util/custom_widget.dart';
import '../util/extension_helper.dart';
import 'episode_download.dart';
@ -34,6 +35,7 @@ class EpisodeDetail extends StatefulWidget {
class _EpisodeDetailState extends State<EpisodeDetail> {
final textstyle = TextStyle(fontSize: 15.0, color: Colors.black);
final GlobalKey<AudioPanelState> _playerKey = GlobalKey<AudioPanelState>();
double downloadProgress;
/// Show page title.
@ -122,245 +124,258 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
systemNavigationBarIconBrightness:
Theme.of(context).accentColorBrightness,
),
child: Scaffold(
backgroundColor: Theme.of(context).primaryColor,
appBar: AppBar(
title: _showTitle
? Text(
widget.episodeItem.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
: Center(),
elevation: _showTitle ? 1 : 0,
actions: [
PopupMenuButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
elevation: 1,
tooltip: s.menu,
itemBuilder: (context) => [
PopupMenuItem(
value: 0,
child: Container(
padding: EdgeInsets.only(left: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 25,
height: 25,
child: CustomPaint(
painter: ListenedAllPainter(
context.textTheme.bodyText1.color,
stroke: 2)),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 5.0),
),
Text(
s.markListened,
),
],
),
),
),
],
onSelected: (value) async {
switch (value) {
case 0:
await _markListened(widget.episodeItem);
if (mounted) setState(() {});
Fluttertoast.showToast(
msg: s.markListened,
gravity: ToastGravity.BOTTOM,
);
break;
default:
break;
}
},
),
],
),
body: Stack(
children: <Widget>[
Container(
color: Theme.of(context).primaryColor,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
controller: _controller,
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.episodeItem.title,
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.headline5,
),
),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(
left: 20.0, right: 20, top: 10, bottom: 10),
child: Text(
s.published(DateFormat.yMMMd().format(
DateTime.fromMillisecondsSinceEpoch(
widget.episodeItem.pubDate))),
style:
TextStyle(color: Theme.of(context).accentColor)),
),
Padding(
padding: EdgeInsets.only(
left: 20.0, right: 20, top: 10, bottom: 10),
child: WillPopScope(
onWillPop: () async {
if (_playerKey.currentState != null &&
_playerKey.currentState.initSize > 100) {
_playerKey.currentState.backToMini();
return false;
} else {
return true;
}
},
child: Scaffold(
backgroundColor: Theme.of(context).primaryColor,
appBar: AppBar(
title: _showTitle
? Text(
widget.episodeItem.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
: Center(),
elevation: _showTitle ? 1 : 0,
actions: [
PopupMenuButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
elevation: 1,
tooltip: s.menu,
itemBuilder: (context) => [
PopupMenuItem(
value: 0,
child: Container(
padding: EdgeInsets.only(left: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
if (widget.episodeItem.explicit == 1)
Container(
decoration: BoxDecoration(
color: Colors.red[800],
shape: BoxShape.circle),
height: 25.0,
width: 25.0,
margin: EdgeInsets.only(right: 10.0),
alignment: Alignment.center,
child: Text('E',
style: TextStyle(color: Colors.white))),
if (widget.episodeItem.duration != 0)
Container(
decoration: BoxDecoration(
color: Colors.cyan[300],
borderRadius:
BorderRadius.all(Radius.circular(15.0))),
height: 25.0,
margin: EdgeInsets.only(right: 10.0),
padding: EdgeInsets.symmetric(horizontal: 10.0),
alignment: Alignment.center,
child: Text(
s.minsCount(
widget.episodeItem.duration ~/ 60),
style: textstyle),
),
if (widget.episodeItem.enclosureLength != null &&
widget.episodeItem.enclosureLength != 0)
Container(
decoration: BoxDecoration(
color: Colors.lightBlue[300],
borderRadius:
BorderRadius.all(Radius.circular(15.0))),
height: 25.0,
margin: EdgeInsets.only(right: 10.0),
padding: EdgeInsets.symmetric(horizontal: 10.0),
alignment: Alignment.center,
child: Text(
'${(widget.episodeItem.enclosureLength) ~/ 1000000}MB',
style: textstyle),
),
SizedBox(
width: 25,
height: 25,
child: CustomPaint(
painter: ListenedAllPainter(
context.textTheme.bodyText1.color,
stroke: 2)),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 5.0),
),
Text(
s.markListened,
),
],
),
),
_loaddes
? (_description.contains('<'))
? Html(
padding: EdgeInsets.only(
left: 20.0, right: 20, bottom: 50),
defaultTextStyle:
// GoogleFonts.libreBaskerville(
GoogleFonts.martel(
textStyle: TextStyle(
height: 1.8,
),
],
onSelected: (value) async {
switch (value) {
case 0:
await _markListened(widget.episodeItem);
if (mounted) setState(() {});
Fluttertoast.showToast(
msg: s.markListened,
gravity: ToastGravity.BOTTOM,
);
break;
default:
break;
}
},
),
],
),
body: Stack(
children: <Widget>[
Container(
color: Theme.of(context).primaryColor,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
controller: _controller,
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.episodeItem.title,
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.headline5,
),
),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(
left: 20.0, right: 20, top: 10, bottom: 10),
child: Text(
s.published(DateFormat.yMMMd().format(
DateTime.fromMillisecondsSinceEpoch(
widget.episodeItem.pubDate))),
style: TextStyle(
color: Theme.of(context).accentColor)),
),
Padding(
padding: EdgeInsets.only(
left: 20.0, right: 20, top: 10, bottom: 10),
child: Row(
children: <Widget>[
if (widget.episodeItem.explicit == 1)
Container(
decoration: BoxDecoration(
color: Colors.red[800],
shape: BoxShape.circle),
height: 25.0,
width: 25.0,
margin: EdgeInsets.only(right: 10.0),
alignment: Alignment.center,
child: Text('E',
style: TextStyle(color: Colors.white))),
if (widget.episodeItem.duration != 0)
Container(
decoration: BoxDecoration(
color: Colors.cyan[300],
borderRadius: BorderRadius.all(
Radius.circular(15.0))),
height: 25.0,
margin: EdgeInsets.only(right: 10.0),
padding: EdgeInsets.symmetric(horizontal: 10.0),
alignment: Alignment.center,
child: Text(
s.minsCount(
widget.episodeItem.duration ~/ 60),
style: textstyle),
),
if (widget.episodeItem.enclosureLength != null &&
widget.episodeItem.enclosureLength != 0)
Container(
decoration: BoxDecoration(
color: Colors.lightBlue[300],
borderRadius: BorderRadius.all(
Radius.circular(15.0))),
height: 25.0,
margin: EdgeInsets.only(right: 10.0),
padding: EdgeInsets.symmetric(horizontal: 10.0),
alignment: Alignment.center,
child: Text(
'${(widget.episodeItem.enclosureLength) ~/ 1000000}MB',
style: textstyle),
),
],
),
),
_loaddes
? (_description.contains('<'))
? Html(
padding: EdgeInsets.only(
left: 20.0, right: 20, bottom: 50),
defaultTextStyle:
// GoogleFonts.libreBaskerville(
GoogleFonts.martel(
textStyle: TextStyle(
height: 1.8,
),
),
),
data: _description,
linkStyle: TextStyle(
color: context.accentColor,
// decoration: TextDecoration.underline,
textBaseline: TextBaseline.ideographic),
onLinkTap: (url) {
_launchUrl(url);
},
useRichText: true,
)
: _description.length > 0
? Container(
padding: EdgeInsets.only(
left: 20.0, right: 20.0, bottom: 50.0),
alignment: Alignment.topLeft,
child: SelectableLinkify(
onOpen: (link) {
_launchUrl(link.url);
},
text: _description,
style: GoogleFonts.martel(
textStyle: TextStyle(
height: 1.8,
data: _description,
linkStyle: TextStyle(
color: context.accentColor,
// decoration: TextDecoration.underline,
textBaseline: TextBaseline.ideographic),
onLinkTap: (url) {
_launchUrl(url);
},
useRichText: true,
)
: _description.length > 0
? Container(
padding: EdgeInsets.only(
left: 20.0,
right: 20.0,
bottom: 50.0),
alignment: Alignment.topLeft,
child: SelectableLinkify(
onOpen: (link) {
_launchUrl(link.url);
},
text: _description,
style: GoogleFonts.martel(
textStyle: TextStyle(
height: 1.8,
),
),
linkStyle: TextStyle(
color: Theme.of(context).accentColor,
// decoration:
// TextDecoration.underline,
),
),
linkStyle: TextStyle(
color: Theme.of(context).accentColor,
// decoration:
// TextDecoration.underline,
)
: Container(
height: context.width,
alignment: Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Image(
image: AssetImage(
'assets/shownote.png'),
height: 100.0,
),
Padding(padding: EdgeInsets.all(5.0)),
Text(s.noShownote,
textAlign: TextAlign.center,
style: TextStyle(
color: context.textColor
.withOpacity(0.5))),
],
),
),
)
: Container(
height: context.width,
alignment: Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Image(
image:
AssetImage('assets/shownote.png'),
height: 100.0,
),
Padding(padding: EdgeInsets.all(5.0)),
Text(s.noShownote,
textAlign: TextAlign.center,
style: TextStyle(
color: context.textColor
.withOpacity(0.5))),
],
),
)
: Center(),
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return Padding(
padding: EdgeInsets.only(bottom: data ? 60.0 : 0),
);
}),
],
)
: Center(),
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return SizedBox(
height: data ? 70.0 : 0,
);
}),
],
),
),
),
),
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return Container(
alignment: Alignment.bottomCenter,
padding: EdgeInsets.only(bottom: data ? 60.0 : 0),
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
height: !_showMenu ? 50 : 0,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: MenuBar(
episodeItem: widget.episodeItem,
heroTag: widget.heroTag,
hide: widget.hide),
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return Container(
alignment: Alignment.bottomCenter,
padding: EdgeInsets.only(bottom: data ? 70.0 : 0),
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
height: !_showMenu ? 50 : 0,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: MenuBar(
episodeItem: widget.episodeItem,
heroTag: widget.heroTag,
hide: widget.hide),
),
),
),
);
}),
Container(child: PlayerWidget()),
],
);
}),
Container(child: PlayerWidget(playerKey: _playerKey)),
],
),
),
),
);

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ import '../state/podcast_group.dart';
import '../state/setting_state.dart';
import '../type/episodebrief.dart';
import '../type/playlist.dart';
import '../util/audiopanel.dart';
import '../util/custom_widget.dart';
import '../util/episodegrid.dart';
import '../util/extension_helper.dart';
@ -44,6 +45,7 @@ class Home extends StatefulWidget {
class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final GlobalKey<AudioPanelState> _playerKey = GlobalKey<AudioPanelState>();
TabController _controller;
Decoration _getIndicator(BuildContext context) {
return UnderlineTabIndicator(
@ -102,10 +104,14 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
systemNavigationBarColor: Theme.of(context).primaryColor,
),
child: Scaffold(
key: _scaffoldKey,
// key: _scaffoldKey,
body: WillPopScope(
onWillPop: () async {
if (Platform.isAndroid) {
if (_playerKey.currentState != null &&
_playerKey.currentState.initSize > 100) {
_playerKey.currentState.backToMini();
return false;
} else if (Platform.isAndroid) {
_androidAppRetain.invokeMethod('sendToBackground');
return false;
} else {
@ -445,7 +451,7 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
}),
],
),
Container(child: PlayerWidget()),
Container(child: PlayerWidget(playerKey: _playerKey)),
],
),
),

View File

@ -21,6 +21,7 @@ import '../type/episodebrief.dart';
import '../type/fireside_data.dart';
import '../type/play_histroy.dart';
import '../type/podcastlocal.dart';
import '../util/audiopanel.dart';
import '../util/custom_widget.dart';
import '../util/episodegrid.dart';
import '../util/extension_helper.dart';
@ -39,6 +40,8 @@ class _PodcastDetailState extends State<PodcastDetail> {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
final GlobalKey<AudioPanelState> _playerKey = GlobalKey<AudioPanelState>();
/// Fireside background if hosted on fireside.
String _backgroundImage;
@ -628,197 +631,218 @@ class _PodcastDetailState extends State<PodcastDetail> {
systemNavigationBarColor: Theme.of(context).primaryColor,
systemNavigationBarIconBrightness:
Theme.of(context).accentColorBrightness,
//statusBarColor: _color,
),
child: Scaffold(
body: SafeArea(
top: false,
minimum: widget.hide ? EdgeInsets.only(bottom: 50) : EdgeInsets.zero,
child: RefreshIndicator(
key: _refreshIndicatorKey,
color: Theme.of(context).accentColor,
onRefresh: () async {
await _updateRssItem(context, widget.podcastLocal);
// audio.addNewEpisode(widget.podcastLocal.id);
},
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: FutureBuilder<List<EpisodeBrief>>(
future: _getRssItem(widget.podcastLocal,
count: _top,
reverse: _reverse,
filter: _filter,
query: _query),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return (snapshot.hasData)
? CustomScrollView(
controller: _controller
..addListener(() async {
if (_controller.offset ==
_controller
.position.maxScrollExtent &&
snapshot.data.length == _top) {
if (mounted) {
setState(() => _loadMore = true);
child: WillPopScope(
onWillPop: () {
if (_playerKey.currentState != null &&
_playerKey.currentState.initSize > 100) {
_playerKey.currentState.backToMini();
return Future.value(false);
} else {
return Future.value(true);
}
},
child: Scaffold(
body: SafeArea(
top: false,
minimum:
widget.hide ? EdgeInsets.only(bottom: 50) : EdgeInsets.zero,
child: RefreshIndicator(
key: _refreshIndicatorKey,
color: Theme.of(context).accentColor,
onRefresh: () async {
await _updateRssItem(context, widget.podcastLocal);
// audio.addNewEpisode(widget.podcastLocal.id);
},
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: FutureBuilder<List<EpisodeBrief>>(
future: _getRssItem(widget.podcastLocal,
count: _top,
reverse: _reverse,
filter: _filter,
query: _query),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return (snapshot.hasData)
? CustomScrollView(
controller: _controller
..addListener(() async {
if (_controller.offset ==
_controller
.position.maxScrollExtent &&
snapshot.data.length == _top) {
if (mounted) {
setState(() => _loadMore = true);
}
await Future.delayed(
Duration(seconds: 3));
if (mounted) {
setState(() {
_top = _top + 36;
_loadMore = false;
});
}
}
await Future.delayed(
Duration(seconds: 3));
if (mounted) {
setState(() {
_top = _top + 36;
_loadMore = false;
});
if (_controller.offset > 0 &&
mounted &&
!_scroll) {
setState(() => _scroll = true);
}
}
if (_controller.offset > 0 &&
mounted &&
!_scroll) {
setState(() => _scroll = true);
}
}),
physics:
const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[
SliverAppBar(
brightness: Brightness.dark,
actions: <Widget>[_rightTopMenu(context)],
elevation: 0,
iconTheme: IconThemeData(
color: Colors.white,
),
expandedHeight: 150 + context.paddingTop,
backgroundColor: _color,
floating: true,
pinned: true,
flexibleSpace: LayoutBuilder(
builder: (context, constraints) {
_topHeight = constraints.biggest.height;
return FlexibleSpaceBar(
background: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 120 +
context.paddingTop),
padding: EdgeInsets.only(
left: 80, right: 120),
color: Colors.white10,
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
mainAxisSize:
MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.podcastLocal
.author ??
'',
maxLines: 1,
overflow: TextOverflow
.ellipsis,
style: TextStyle(
color:
Colors.white)),
if (widget.podcastLocal
.provider.isNotEmpty)
Text(
s.hostedOn(widget
.podcastLocal
.provider),
maxLines: 1,
style: TextStyle(
color:
Colors.white),
),
],
),
),
Container(
alignment:
Alignment.centerRight,
padding:
EdgeInsets.only(right: 10),
child: SizedBox(
height: 120,
child: Image.file(File(
"${widget.podcastLocal.imagePath}")),
),
),
Container(
alignment: Alignment.center,
child: podcastInfo(context),
),
],
),
title: _topHeight <
70 + context.paddingTop
? Text(widget.podcastLocal.title,
maxLines: 1,
overflow:
TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white))
: Center(),
);
}),
),
SliverToBoxAdapter(
child: hostsList(context, _hosts),
),
SliverToBoxAdapter(
child: _actionBar(context)),
EpisodeGrid(
episodes: snapshot.data,
showFavorite: true,
showNumber: _filter == Filter.all &&
!_hideListened
? true
: false,
layout: _layout,
reverse: _reverse,
episodeCount: _episodeCount,
initNum: _scroll ? 0 : 12,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return _loadMore
? Container(
height: 2,
child:
LinearProgressIndicator())
: Center();
},
childCount: 1,
physics:
const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[
SliverAppBar(
brightness: Brightness.dark,
actions: <Widget>[
_rightTopMenu(context)
],
elevation: 0,
iconTheme: IconThemeData(
color: Colors.white,
),
expandedHeight:
150 + context.paddingTop,
backgroundColor: _color,
floating: true,
pinned: true,
flexibleSpace: LayoutBuilder(
builder: (context, constraints) {
_topHeight =
constraints.biggest.height;
return FlexibleSpaceBar(
background: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 120 +
context.paddingTop),
padding: EdgeInsets.only(
left: 80, right: 120),
color: Colors.white10,
alignment:
Alignment.centerLeft,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
mainAxisSize:
MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment
.start,
children: <Widget>[
Text(
widget.podcastLocal
.author ??
'',
maxLines: 1,
overflow: TextOverflow
.ellipsis,
style: TextStyle(
color: Colors
.white)),
if (widget.podcastLocal
.provider.isNotEmpty)
Text(
s.hostedOn(widget
.podcastLocal
.provider),
maxLines: 1,
style: TextStyle(
color:
Colors.white),
),
],
),
),
Container(
alignment:
Alignment.centerRight,
padding: EdgeInsets.only(
right: 10),
child: SizedBox(
height: 120,
child: Image.file(File(
"${widget.podcastLocal.imagePath}")),
),
),
Container(
alignment: Alignment.center,
child: podcastInfo(context),
),
],
),
title: _topHeight <
70 + context.paddingTop
? Text(
widget.podcastLocal.title,
maxLines: 1,
overflow:
TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white))
: Center(),
);
}),
),
),
],
)
: Center(child: CircularProgressIndicator());
},
SliverToBoxAdapter(
child: hostsList(context, _hosts),
),
SliverToBoxAdapter(
child: _actionBar(context)),
EpisodeGrid(
episodes: snapshot.data,
showFavorite: true,
showNumber: _filter == Filter.all &&
!_hideListened
? true
: false,
layout: _layout,
reverse: _reverse,
episodeCount: _episodeCount,
initNum: _scroll ? 0 : 12,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return _loadMore
? Container(
height: 2,
child:
LinearProgressIndicator())
: Center();
},
childCount: 1,
),
),
],
)
: Center(child: CircularProgressIndicator());
},
),
),
),
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return Padding(
padding: EdgeInsets.only(bottom: data ? 60.0 : 0),
);
}),
],
),
Container(child: PlayerWidget()),
],
Selector<AudioPlayerNotifier, bool>(
selector: (_, audio) => audio.playerRunning,
builder: (_, data, __) {
return SizedBox(
height: data ? 70.0 : 0,
);
}),
],
),
Container(
child: PlayerWidget(
playerKey: _playerKey,
)),
],
),
),
),
),

View File

@ -10,23 +10,22 @@ class AudioPanel extends StatefulWidget {
final Widget miniPanel;
final Widget expandedPanel;
final Widget optionPanel;
final Widget cover;
final double minHeight;
final double maxHeight;
AudioPanel(
{@required this.miniPanel,
@required this.expandedPanel,
this.optionPanel,
this.cover,
this.minHeight = 60,
this.minHeight = 70,
this.maxHeight = 300,
Key key})
: super(key: key);
@override
_AudioPanelState createState() => _AudioPanelState();
AudioPanelState createState() => AudioPanelState();
}
class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
class AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
double initSize;
double _startdy;
double _move = 0;
@ -81,7 +80,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
child: (_animation.value > widget.minHeight + 30)
? Positioned.fill(
child: GestureDetector(
onTap: _backToMini,
onTap: backToMini,
child: Container(
color: Theme.of(context)
.scaffoldBackgroundColor
@ -92,7 +91,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
)
: Center(),
),
Container(
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onVerticalDragStart: _start,
@ -107,9 +106,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
opacity: _animation.value > widget.minHeight
? (widget.minHeight + 30 - _animation.value) / 40
: 1,
child: Container(
child: widget.miniPanel,
),
child: widget.miniPanel,
),
)
: Container(
@ -117,12 +114,11 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
color: context.primaryColor,
boxShadow: [
BoxShadow(
offset: Offset(0, -0.5),
offset: Offset(0, -1),
blurRadius: 1,
color:
Theme.of(context).brightness == Brightness.light
? Colors.grey[400].withOpacity(0.5)
: Colors.grey[800],
color: context.brightness == Brightness.light
? Colors.grey[400].withOpacity(0.5)
: Colors.grey[800],
),
],
),
@ -133,7 +129,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
? (_animation.value - widget.minHeight) /
(widget.maxHeight - widget.minHeight - 50)
: 1,
child: Container(
child: SizedBox(
height: math.max(widget.maxHeight,
math.min(_animation.value, _expandHeight)),
child: widget.expandedPanel,
@ -147,7 +143,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
]);
}
_backToMini() {
backToMini() {
setState(() {
_animation = Tween<double>(begin: initSize, end: widget.minHeight)
.animate(_slowController);
@ -156,6 +152,15 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
_slowController.forward();
}
scrollToTop() {
setState(() {
_animation = Tween<double>(begin: initSize, end: _expandHeight)
.animate(_slowController);
initSize = _expandHeight;
});
_slowController.forward();
}
_start(DragStartDetails event) {
setState(() {
_startdy = event.localPosition.dy;
@ -175,7 +180,7 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
_controller.forward();
}
_end() {
_end() async {
if (_slideDirection == SlideDirection.up) {
if (_move > 20) {
if (_animation.value > widget.maxHeight + 20) {
@ -185,15 +190,16 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
.animate(_slowController);
initSize = _expandHeight;
});
_slowController.forward();
} else {
setState(() {
_animation =
Tween<double>(begin: _animation.value, end: widget.maxHeight)
.animate(_slowController);
Tween<double>(begin: widget.maxHeight, end: widget.maxHeight)
.animate(_controller);
initSize = widget.maxHeight;
});
_controller.forward();
}
_slowController.forward();
} else {
setState(() {
_animation =
@ -251,3 +257,64 @@ class _AudioPanelState extends State<AudioPanel> with TickerProviderStateMixin {
}
}
}
class _AudioPanelRoute extends StatefulWidget {
_AudioPanelRoute({this.expandPanel, this.height, Key key}) : super(key: key);
final Widget expandPanel;
final double height;
@override
__AudioPanelRouteState createState() => __AudioPanelRouteState();
}
class __AudioPanelRouteState extends State<_AudioPanelRoute> {
@override
Widget build(BuildContext context) {
return MediaQuery.removePadding(
context: context,
removeTop: true,
child: Scaffold(
body: Stack(children: <Widget>[
Container(
child: Positioned.fill(
child: GestureDetector(
onTap: () => Navigator.pop(context),
// child:
// Container(
// color: Theme.of(context)
// .scaffoldBackgroundColor
// .withOpacity(0.8),
//
//),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: widget.height,
decoration: BoxDecoration(
color: context.primaryColor,
boxShadow: [
BoxShadow(
offset: Offset(0, -1),
blurRadius: 1,
color: context.brightness == Brightness.light
? Colors.grey[400].withOpacity(0.5)
: Colors.grey[800],
),
],
),
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: SizedBox(
height: 300,
child: widget.expandPanel,
),
),
),
),
]),
),
);
}
}

View File

@ -1000,3 +1000,84 @@ class LayoutButton extends StatelessWidget {
);
}
}
/// Remove scroll view overlay effect.
class NoGrowBehavior extends ScrollBehavior {
@override
Widget buildViewportChrome(
BuildContext context, Widget child, AxisDirection axisDirection) {
return child;
}
}
class Meteor extends CustomPainter {
Paint _paint;
Meteor() {
_paint = Paint()
..color = Colors.white
..strokeWidth = 2.0
..strokeCap = StrokeCap.round;
}
@override
void paint(Canvas canvas, Size size) {
canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), _paint);
}
@override
bool shouldRepaint(Meteor oldDelegate) {
return false;
}
}
/// Used in sleep mode widget.
class MeteorLoader extends StatefulWidget {
@override
_MeteorLoaderState createState() => _MeteorLoaderState();
}
class _MeteorLoaderState extends State<MeteorLoader>
with SingleTickerProviderStateMixin {
double _fraction = 0.0;
double _move = 0.0;
Animation animation;
AnimationController controller;
@override
void initState() {
super.initState();
controller =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
if (mounted) {
setState(() {
_move = animation.value;
if (animation.value <= 0.5) {
_fraction = animation.value * 2;
} else {
_fraction = 2 - (animation.value) * 2;
}
});
}
});
controller.forward();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Positioned(
top: 300 * _move + 10,
left: 150 * _move + 50,
child: SizedBox(
width: 50 * _fraction,
height: 100 * _fraction,
child: CustomPaint(painter: Meteor())),
);
}
}

View File

@ -725,7 +725,7 @@ class _OpenContainerRoute extends ModalRoute<void> {
_positionTween.end = Offset(
10,
playerRunning
? MediaQuery.of(context).size.height - 100
? MediaQuery.of(context).size.height - 110
: MediaQuery.of(context).size.height - 40);
var _width = MediaQuery.of(context).size.width;