Fixes, elevation property

This commit is contained in:
peterscodee 2020-07-30 17:01:37 +02:00
parent f18eb5033a
commit 9e6dd01e02
2 changed files with 53 additions and 42 deletions

View File

@ -11,14 +11,16 @@ class Miniplayer extends StatefulWidget {
final double maxHeight; final double maxHeight;
final MiniplayerBuilder builder; final MiniplayerBuilder builder;
final Curve curve; final Curve curve;
final double elevation;
const Miniplayer( const Miniplayer({
{Key key, Key key,
@required this.minHeight, @required this.minHeight,
@required this.maxHeight, @required this.maxHeight,
@required this.builder, @required this.builder,
this.curve = Curves.easeInQuart}) this.curve = Curves.easeInQuart,
: super(key: key); this.elevation = 0,
}) : super(key: key);
@override @override
_MiniplayerState createState() => _MiniplayerState(); _MiniplayerState createState() => _MiniplayerState();
@ -84,41 +86,50 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
child: Container( child: Container(
color: Colors.black.withOpacity(_percentage * 0.5)), color: Colors.black.withOpacity(_percentage * 0.5)),
), ),
SizedBox( Align(
height: snapshot.data, alignment: Alignment.bottomCenter,
child: GestureDetector( child: SizedBox(
child: widget.builder(snapshot.data, _percentage), height: snapshot.data,
onTap: () { child: GestureDetector(
bool up = _height != widget.maxHeight; child: Material(
animateToHeight(up ? widget.maxHeight : widget.minHeight); elevation: widget.elevation,
}, child: Container(
onPanEnd: (details) async { constraints: BoxConstraints.expand(),
if (_up) child: widget.builder(snapshot.data, _percentage),
animateToHeight(widget.maxHeight); ),
else ),
animateToHeight(widget.minHeight); onTap: () {
}, bool up = _height != widget.maxHeight;
onPanUpdate: (details) { animateToHeight(up ? widget.maxHeight : widget.minHeight);
_prevHeight = _height; },
var h = _height -= onPanEnd: (details) async {
details.delta.dy; //details.delta.dy < 0 -> -- = + if (_up)
animateToHeight(widget.maxHeight);
else
animateToHeight(widget.minHeight);
},
onPanUpdate: (details) {
_prevHeight = _height;
var h = _height -=
details.delta.dy; //details.delta.dy < 0 -> -- = +
//Make sure height !> maxHeight && !< minHeight //Make sure height !> maxHeight && !< minHeight
if (h > widget.maxHeight) if (h > widget.maxHeight)
h = widget.maxHeight; h = widget.maxHeight;
else if (h < widget.minHeight) h = widget.minHeight; else if (h < widget.minHeight) h = widget.minHeight;
if (_prevHeight == h && if (_prevHeight == h &&
(h == widget.minHeight || h == widget.maxHeight)) (h == widget.minHeight || h == widget.maxHeight))
return; return;
//print('h: ' + h.toString()); //print('h: ' + h.toString());
_height = h; _height = h;
_up = _prevHeight < _height; _up = _prevHeight < _height;
_heightController.add(h); _heightController.add(h);
}, },
),
), ),
), ),
], ],

View File

@ -1,12 +1,12 @@
name: miniplayer name: miniplayer
description: Miniplayer for Flutter description: Miniplayer for Flutter
version: 0.0.1 version: 0.1.0
author: David Peters homepage: https://www.peterscode.dev
homepage: peterscode.dev repository: https://github.com/peterscodee/miniplayer
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.3.0 <3.0.0"
flutter: ">=1.17.0 <2.0.0" flutter: ">=1.0.0 <2.0.0"
dependencies: dependencies:
flutter: flutter: