2020-02-09 13:29:09 +01:00
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_html/flutter_html.dart';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-02-13 03:51:46 +01:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-02-11 14:48:11 +01:00
|
|
|
import 'package:tsacdop/class/audiostate.dart';
|
|
|
|
import 'package:tsacdop/class/episodebrief.dart';
|
|
|
|
import 'package:tsacdop/class/sqflite_localpodcast.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'episodedownload.dart';
|
|
|
|
|
|
|
|
enum DownloadState { stop, load, donwload, complete, error }
|
|
|
|
|
|
|
|
class EpisodeDetail extends StatefulWidget {
|
|
|
|
final EpisodeBrief episodeItem;
|
|
|
|
final String heroTag;
|
|
|
|
EpisodeDetail({this.episodeItem, this.heroTag, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_EpisodeDetailState createState() => _EpisodeDetailState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EpisodeDetailState extends State<EpisodeDetail> {
|
|
|
|
final textstyle = TextStyle(fontSize: 15.0, color: Colors.black);
|
|
|
|
double downloadProgress;
|
|
|
|
bool _loaddes;
|
|
|
|
Future getSDescription(String title) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
widget.episodeItem.description = await dbHelper.getDescription(title);
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
_loaddes = true;
|
|
|
|
});
|
|
|
|
}
|
2020-02-11 14:01:57 +01:00
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
_launchUrl(String url) async {
|
2020-02-11 14:01:57 +01:00
|
|
|
if (await canLaunch(url)) {
|
|
|
|
await launch(url);
|
|
|
|
} else {
|
|
|
|
throw 'Could not launch $url';
|
|
|
|
}
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
2020-02-11 14:01:57 +01:00
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loaddes = false;
|
|
|
|
getSDescription(widget.episodeItem.title);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.grey[100],
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(widget.episodeItem.feedTitle),
|
|
|
|
elevation: 0.0,
|
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: Colors.grey[100],
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
color: Colors.grey[100],
|
|
|
|
padding: EdgeInsets.all(12.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.0),
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Text(
|
|
|
|
widget.episodeItem.title,
|
|
|
|
style: Theme.of(context).textTheme.title,
|
|
|
|
),
|
|
|
|
),
|
2020-02-11 14:01:57 +01:00
|
|
|
Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.0),
|
|
|
|
height: 30.0,
|
|
|
|
child: Text(
|
|
|
|
'Published ' +
|
|
|
|
widget.episodeItem.pubDate.substring(0, 16),
|
|
|
|
style: TextStyle(color: Colors.blue[500])),
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(12.0),
|
2020-02-11 14:01:57 +01:00
|
|
|
height: 50.0,
|
2020-02-09 13:29:09 +01:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
(widget.episodeItem.explicit == 1)
|
2020-02-12 16:16:46 +01:00
|
|
|
? 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)))
|
2020-02-09 13:29:09 +01:00
|
|
|
: Center(),
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.cyan[300],
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(15.0))),
|
|
|
|
height: 30.0,
|
|
|
|
margin: EdgeInsets.only(right: 10.0),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
(widget.episodeItem.duration).toString() + 'mins',
|
|
|
|
style: textstyle),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.lightBlue[300],
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(15.0))),
|
|
|
|
height: 30.0,
|
|
|
|
margin: EdgeInsets.only(right: 10.0),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
((widget.episodeItem.enclosureLength) ~/ 1000000)
|
|
|
|
.toString() +
|
|
|
|
'MB',
|
|
|
|
style: textstyle),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 12.0, right: 12.0, top: 5.0),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: (widget.episodeItem.description != null && _loaddes)
|
2020-02-11 14:01:57 +01:00
|
|
|
? Html(
|
|
|
|
data: widget.episodeItem.description,
|
|
|
|
onLinkTap: (url) {
|
|
|
|
_launchUrl(url);
|
|
|
|
},
|
|
|
|
useRichText: true,
|
|
|
|
)
|
2020-02-09 13:29:09 +01:00
|
|
|
: Center(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
MenuBar(
|
|
|
|
episodeItem: widget.episodeItem,
|
|
|
|
heroTag: widget.heroTag,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MenuBar extends StatefulWidget {
|
|
|
|
final EpisodeBrief episodeItem;
|
|
|
|
final String heroTag;
|
|
|
|
MenuBar({this.episodeItem, this.heroTag, Key key}) : super(key: key);
|
|
|
|
@override
|
|
|
|
_MenuBarState createState() => _MenuBarState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MenuBarState extends State<MenuBar> {
|
|
|
|
bool _liked;
|
|
|
|
int _like;
|
|
|
|
|
|
|
|
Future<int> saveLiked(String title) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
int result = await dbHelper.setLiked(title);
|
|
|
|
if (result == 1 && mounted) setState(() => _liked = true);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<int> setUnliked(String title) async {
|
|
|
|
var dbHelper = DBHelper();
|
|
|
|
int result = await dbHelper.setUniked(title);
|
|
|
|
if (result == 1 && mounted)
|
|
|
|
setState(() {
|
|
|
|
_liked = false;
|
|
|
|
_like = 0;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_liked = false;
|
|
|
|
_like = widget.episodeItem.liked;
|
|
|
|
}
|
|
|
|
|
2020-02-13 03:51:46 +01:00
|
|
|
Widget _buttonOnMenu(Widget widget, Function() onTap) => Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
onTap: onTap,
|
|
|
|
child: Container(
|
|
|
|
height: 50.0,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 15.0),
|
|
|
|
child: widget),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final urlChange = Provider.of<Urlchange>(context);
|
|
|
|
return Consumer<Urlchange>(
|
|
|
|
builder: (context, urlchange, _) => Container(
|
|
|
|
height: 50.0,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
(widget.episodeItem.title == urlChange.title &&
|
|
|
|
urlChange.audioState == AudioState.play)
|
|
|
|
? ImageRotate(
|
|
|
|
url: widget.episodeItem.imageUrl,
|
|
|
|
)
|
|
|
|
: Hero(
|
|
|
|
tag: widget.episodeItem.enclosureUrl + widget.heroTag,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(15.0)),
|
|
|
|
child: Container(
|
|
|
|
height: 30.0,
|
|
|
|
width: 30.0,
|
|
|
|
color: Colors.white,
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
imageUrl: widget.episodeItem.imageUrl,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(_like == 0 && !_liked)
|
2020-02-13 03:51:46 +01:00
|
|
|
? _buttonOnMenu(
|
|
|
|
Icon(
|
|
|
|
Icons.favorite_border,
|
|
|
|
color: Colors.grey[700],
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
2020-02-13 03:51:46 +01:00
|
|
|
() => saveLiked(widget.episodeItem.title))
|
2020-02-15 07:39:42 +01:00
|
|
|
: Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
LoveOpen(),
|
|
|
|
_buttonOnMenu(
|
|
|
|
Icon(
|
|
|
|
Icons.favorite,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
() => setUnliked(widget.episodeItem.title)),
|
|
|
|
],
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
DownloadButton(episodeBrief: widget.episodeItem),
|
2020-02-13 03:51:46 +01:00
|
|
|
_buttonOnMenu(Icon(Icons.playlist_add, color: Colors.grey[700]),
|
|
|
|
() {
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Not support yet',
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
);
|
|
|
|
/*TODO*/
|
|
|
|
}),
|
2020-02-09 13:29:09 +01:00
|
|
|
Spacer(),
|
|
|
|
(widget.episodeItem.title != urlchange.title)
|
2020-02-13 03:51:46 +01:00
|
|
|
? Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topRight: Radius.circular(5.0),
|
|
|
|
bottomRight: Radius.circular(5.0)),
|
|
|
|
onTap: () {
|
|
|
|
urlChange.audioUrl = widget.episodeItem.enclosureUrl;
|
|
|
|
urlChange.rssTitle = widget.episodeItem.title;
|
|
|
|
urlChange.feedTitle = widget.episodeItem.feedTitle;
|
2020-02-15 07:39:42 +01:00
|
|
|
urlChange.primaryColor =
|
|
|
|
widget.episodeItem.primaryColor;
|
2020-02-13 03:51:46 +01:00
|
|
|
},
|
|
|
|
child: Container(
|
2020-02-16 09:25:53 +01:00
|
|
|
alignment: Alignment.center,
|
2020-02-13 03:51:46 +01:00
|
|
|
height: 50.0,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
2020-02-16 09:25:53 +01:00
|
|
|
child:Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Text('Play Now', style: TextStyle(color: Colors.blue, fontSize: 15, fontWeight: FontWeight.bold,)),
|
|
|
|
Icon(Icons.play_arrow, color: Colors.blue,),
|
|
|
|
],
|
2020-02-13 03:51:46 +01:00
|
|
|
),
|
|
|
|
),
|
2020-02-09 13:29:09 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
: (widget.episodeItem.title == urlchange.title &&
|
|
|
|
urlchange.audioState == AudioState.play)
|
|
|
|
? Container(
|
2020-02-16 09:25:53 +01:00
|
|
|
padding: EdgeInsets.only(right: 30),
|
2020-02-09 13:29:09 +01:00
|
|
|
child: SizedBox(
|
2020-02-16 09:25:53 +01:00
|
|
|
width: 20, height: 15, child: WaveLoader()))
|
2020-02-09 13:29:09 +01:00
|
|
|
: Container(
|
2020-02-16 09:25:53 +01:00
|
|
|
padding: EdgeInsets.only(right: 30),
|
2020-02-09 13:29:09 +01:00
|
|
|
child: SizedBox(
|
2020-02-16 09:25:53 +01:00
|
|
|
width: 20,
|
2020-02-09 13:29:09 +01:00
|
|
|
height: 15,
|
|
|
|
child: LineLoader(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LinePainter extends CustomPainter {
|
|
|
|
double _fraction;
|
|
|
|
Paint _paint;
|
|
|
|
LinePainter(this._fraction) {
|
|
|
|
_paint = Paint()
|
|
|
|
..color = Colors.blue
|
|
|
|
..strokeWidth = 2.0
|
|
|
|
..strokeCap = StrokeCap.round;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
canvas.drawLine(Offset(0, size.height / 2.0),
|
|
|
|
Offset(size.width * _fraction, size.height / 2.0), _paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(LinePainter oldDelegate) {
|
|
|
|
return oldDelegate._fraction != _fraction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LineLoader extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LineLoaderState createState() => _LineLoaderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LineLoaderState extends State<LineLoader>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
double _fraction = 0.0;
|
|
|
|
Animation animation;
|
|
|
|
AnimationController controller;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-02-15 07:39:42 +01:00
|
|
|
controller =
|
|
|
|
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
|
2020-02-09 13:29:09 +01:00
|
|
|
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
_fraction = animation.value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
controller.forward();
|
|
|
|
controller.addStatusListener((status) {
|
|
|
|
if (status == AnimationStatus.completed) {
|
|
|
|
controller.reset();
|
|
|
|
} else if (status == AnimationStatus.dismissed) {
|
|
|
|
controller.forward();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CustomPaint(painter: LinePainter(_fraction));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class WavePainter extends CustomPainter {
|
|
|
|
double _fraction;
|
|
|
|
double _value;
|
|
|
|
WavePainter(this._fraction);
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
if (_fraction < 0.5) {
|
|
|
|
_value = _fraction;
|
|
|
|
} else {
|
|
|
|
_value = 1 - _fraction;
|
|
|
|
}
|
|
|
|
Path _path = Path();
|
|
|
|
Paint _paint = Paint()
|
|
|
|
..color = Colors.blue
|
|
|
|
..strokeWidth = 2.0
|
|
|
|
..strokeCap = StrokeCap.round
|
|
|
|
..style = PaintingStyle.stroke;
|
|
|
|
_path.moveTo(0, size.height / 2);
|
|
|
|
_path.lineTo(0, size.height / 2 + size.height * _value * 0.2);
|
|
|
|
_path.moveTo(0, size.height / 2);
|
|
|
|
_path.lineTo(0, size.height / 2 - size.height * _value * 0.2);
|
|
|
|
_path.moveTo(size.width / 4, size.height / 2);
|
|
|
|
_path.lineTo(size.width / 4, size.height / 2 + size.height * _value * 0.8);
|
|
|
|
_path.moveTo(size.width / 4, size.height / 2);
|
|
|
|
_path.lineTo(size.width / 4, size.height / 2 - size.height * _value * 0.8);
|
|
|
|
_path.moveTo(size.width / 2, size.height / 2);
|
|
|
|
_path.lineTo(size.width / 2, size.height / 2 + size.height * _value * 0.5);
|
|
|
|
_path.moveTo(size.width / 2, size.height / 2);
|
|
|
|
_path.lineTo(size.width / 2, size.height / 2 - size.height * _value * 0.5);
|
|
|
|
_path.moveTo(size.width * 3 / 4, size.height / 2);
|
|
|
|
_path.lineTo(
|
|
|
|
size.width * 3 / 4, size.height / 2 + size.height * _value * 0.6);
|
|
|
|
_path.moveTo(size.width * 3 / 4, size.height / 2);
|
|
|
|
_path.lineTo(
|
|
|
|
size.width * 3 / 4, size.height / 2 - size.height * _value * 0.6);
|
|
|
|
_path.moveTo(size.width, size.height / 2);
|
|
|
|
_path.lineTo(size.width, size.height / 2 + size.height * _value * 0.2);
|
|
|
|
_path.moveTo(size.width, size.height / 2);
|
|
|
|
_path.lineTo(size.width, size.height / 2 - size.height * _value * 0.2);
|
|
|
|
canvas.drawPath(_path, _paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(WavePainter oldDelegate) {
|
|
|
|
return oldDelegate._fraction != _fraction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class WaveLoader extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_WaveLoaderState createState() => _WaveLoaderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WaveLoaderState extends State<WaveLoader>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
double _fraction = 0.0;
|
|
|
|
Animation animation;
|
|
|
|
AnimationController _controller;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_controller = AnimationController(
|
|
|
|
vsync: this, duration: Duration(milliseconds: 1000));
|
|
|
|
animation = Tween(begin: 0.0, end: 1.0).animate(_controller)
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
_fraction = animation.value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
_controller.addStatusListener((status) {
|
|
|
|
if (status == AnimationStatus.completed) {
|
|
|
|
_controller.reset();
|
|
|
|
} else if (status == AnimationStatus.dismissed) {
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CustomPaint(painter: WavePainter(_fraction));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImageRotate extends StatefulWidget {
|
|
|
|
final String url;
|
|
|
|
ImageRotate({this.url, Key key}) : super(key: key);
|
|
|
|
@override
|
|
|
|
_ImageRotateState createState() => _ImageRotateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ImageRotateState extends State<ImageRotate>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
Animation _animation;
|
|
|
|
AnimationController _controller;
|
|
|
|
double _value;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2020-02-14 07:27:40 +01:00
|
|
|
_value = 0;
|
2020-02-09 13:29:09 +01:00
|
|
|
_controller = AnimationController(
|
|
|
|
vsync: this,
|
|
|
|
duration: Duration(milliseconds: 2000),
|
|
|
|
);
|
|
|
|
_animation = Tween(begin: 0.0, end: 1.0).animate(_controller)
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted)
|
|
|
|
setState(() {
|
|
|
|
_value = _animation.value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_controller.forward();
|
|
|
|
_controller.addStatusListener((status) {
|
|
|
|
if (status == AnimationStatus.completed) {
|
|
|
|
_controller.reset();
|
|
|
|
} else if (status == AnimationStatus.dismissed) {
|
|
|
|
_controller.forward();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Transform.rotate(
|
|
|
|
angle: 2 * math.pi * _value,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(15.0)),
|
|
|
|
child: Container(
|
|
|
|
height: 30.0,
|
|
|
|
width: 30.0,
|
|
|
|
color: Colors.white,
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
imageUrl: widget.url,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-02-12 17:10:03 +01:00
|
|
|
}
|
2020-02-15 07:39:42 +01:00
|
|
|
|
|
|
|
class LovePainter extends CustomPainter {
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
Path _path = Path();
|
|
|
|
Paint _paint = Paint()
|
|
|
|
..color = Colors.red
|
|
|
|
..strokeWidth = 2.0
|
|
|
|
..strokeCap = StrokeCap.round;
|
|
|
|
|
|
|
|
_path.moveTo(size.width / 2, size.height / 6);
|
|
|
|
_path.quadraticBezierTo(size.width / 4, 0, size.width / 8, size.height / 6);
|
|
|
|
_path.quadraticBezierTo(
|
|
|
|
0, size.height / 3, size.width / 8, size.height * 0.55);
|
|
|
|
_path.quadraticBezierTo(
|
|
|
|
size.width / 4, size.height * 0.8, size.width / 2, size.height);
|
|
|
|
_path.quadraticBezierTo(size.width * 0.75, size.height * 0.8,
|
|
|
|
size.width * 7 / 8, size.height * 0.55);
|
|
|
|
_path.quadraticBezierTo(
|
|
|
|
size.width, size.height / 3, size.width * 7 / 8, size.height / 6);
|
|
|
|
_path.quadraticBezierTo(
|
|
|
|
size.width * 3 / 4, 0, size.width / 2, size.height / 6);
|
|
|
|
|
|
|
|
canvas.drawPath(_path, _paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LoveOpen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_LoveOpenState createState() => _LoveOpenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoveOpenState extends State<LoveOpen>
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
Animation _animationA;
|
|
|
|
Animation _animationB;
|
|
|
|
AnimationController _controller;
|
|
|
|
|
|
|
|
var rect = RelativeRect.fromLTRB(100, 100, 100, 100);
|
|
|
|
var rectend = RelativeRect.fromLTRB(0, 0, 0, 0);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_controller = AnimationController(
|
|
|
|
vsync: this,
|
|
|
|
duration: Duration(milliseconds: 500),
|
|
|
|
);
|
|
|
|
|
|
|
|
_animationA = Tween(begin: 0.0, end: 1.0).animate(_controller)
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
});
|
|
|
|
_animationB =
|
|
|
|
RelativeRectTween(begin: rect, end: rectend).animate(_controller)
|
|
|
|
..addListener(() {
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
});
|
|
|
|
|
|
|
|
_controller.forward();
|
|
|
|
_controller.addStatusListener((status) {
|
|
|
|
if (status == AnimationStatus.completed) {
|
|
|
|
_controller.reset();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _littleHeart(double scale, double value, double angle) => Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
padding: EdgeInsets.only(left: value),
|
|
|
|
child: ScaleTransition(
|
|
|
|
scale: _animationA,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Transform.rotate(
|
|
|
|
angle: angle,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 5 * scale,
|
|
|
|
width: 6 * scale,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter: LovePainter(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
_littleHeart(1.3, 10, -math.pi/6),
|
|
|
|
_littleHeart(1.5, 3, 0),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
_littleHeart(0.8, 6, math.pi*1.5),
|
|
|
|
_littleHeart(1.2, 24, math.pi/2),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
_littleHeart(1, 8,-math.pi*0.7),
|
|
|
|
_littleHeart(1.3, 8, math.pi),
|
|
|
|
_littleHeart(1.1, 3, -math.pi*1.2)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|