2021-09-29 23:57:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-11 03:00:38 +00:00
|
|
|
import 'package:pikapika/basic/Entities.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
2021-10-27 08:14:35 +00:00
|
|
|
// 继续阅读按钮
|
2021-09-29 23:57:09 +00:00
|
|
|
class ContinueReadButton extends StatefulWidget {
|
|
|
|
final Future<ViewLog?> viewFuture;
|
|
|
|
final Function(int? epOrder, int? pictureRank) onChoose;
|
|
|
|
|
|
|
|
const ContinueReadButton({
|
|
|
|
Key? key,
|
|
|
|
required this.viewFuture,
|
|
|
|
required this.onChoose,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _ContinueReadButtonState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ContinueReadButtonState extends State<ContinueReadButton> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
|
|
var width = constraints.maxWidth;
|
|
|
|
return FutureBuilder(
|
|
|
|
future: widget.viewFuture,
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<ViewLog?> snapshot) {
|
|
|
|
late void Function() onPressed;
|
|
|
|
late String text;
|
|
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
|
|
onPressed = () {};
|
|
|
|
text = '加载中';
|
|
|
|
}
|
|
|
|
if (snapshot.data != null && snapshot.data!.lastViewEpOrder > 0) {
|
|
|
|
onPressed = () => widget.onChoose(
|
|
|
|
snapshot.data?.lastViewEpOrder,
|
|
|
|
snapshot.data?.lastViewPictureRank,
|
|
|
|
);
|
|
|
|
text =
|
2021-11-30 10:49:51 +00:00
|
|
|
'继续阅读 ${snapshot.data?.lastViewEpTitle} P. ${(snapshot.data?.lastViewPictureRank ?? 0) + 1}';
|
2021-09-29 23:57:09 +00:00
|
|
|
} else {
|
|
|
|
onPressed = () => widget.onChoose(null, null);
|
|
|
|
text = '开始阅读';
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
margin: EdgeInsets.only(bottom: 10),
|
|
|
|
width: width,
|
|
|
|
child: MaterialButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1!
|
|
|
|
.color!
|
|
|
|
.withOpacity(.05),
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Text(
|
|
|
|
text,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|