fix any bugs

This commit is contained in:
niuhuan 2021-12-01 09:17:15 +08:00
parent 8ebcccfbf8
commit 20e0ee172c
4 changed files with 346 additions and 224 deletions

View File

@ -11,7 +11,8 @@ import 'package:pikapika/basic/config/Quality.dart';
import 'package:pikapika/basic/config/ReaderDirection.dart';
import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/basic/const.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart';
import 'package:pikapika/screens/components/ContentError.dart';
import 'package:pikapika/screens/components/ContentLoading.dart';
import 'components/ImageReader.dart';
// 线
@ -151,55 +152,92 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
return readerKeyboardHolder(_build(context));
}
Future _onSelectDirection() async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
}
Future _onSelectReaderType() async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
}
Widget _build(BuildContext context) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
backgroundColor: readerAppbarColor,
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: () async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
},
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: () async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
},
icon: Icon(Icons.view_day_outlined),
),
],
return FutureBuilder(
future: _future,
builder: (BuildContext context,
AsyncSnapshot<List<RemoteImageInfo>> snapshot) {
if (snapshot.hasError) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
backgroundColor: readerAppbarColor,
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentError(
error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async {
setState(() {
_future = _load();
});
},
),
body: ContentBuilder(
future: _future,
onRefresh: () async {
setState(() {
_future = _load();
});
},
successBuilder: (BuildContext context,
AsyncSnapshot<List<RemoteImageInfo>> snapshot) {
return ImageReader(
);
}
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
backgroundColor: readerAppbarColor,
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentLoading(label: '加载中'),
);
}
var epNameMap = Map<int, String>();
widget.epList.forEach((element) {
epNameMap[element.order] = element.title;
});
return Scaffold(
body: ImageReader(
ImageReaderStruct(
images: snapshot.data!
.map((e) => ReaderImageInfo(
e.fileServer,
e.path,
null,
null,
null,
null,
null,
))
e.fileServer,
e.path,
null,
null,
null,
null,
null,
))
.toList(),
fullScreen: _fullScreen,
onFullScreenChange: _onFullScreenChange,
@ -210,10 +248,15 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
initPosition: widget.initPicturePosition,
pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection,
epNameMap: epNameMap,
epOrder: _ep.order,
comicTitle: widget.comicInfo.title,
onSelectDirection: _onSelectDirection,
onSelectReaderType: _onSelectReaderType,
),
);
},
),
),
);
},
);
}

View File

@ -10,6 +10,8 @@ import 'package:pikapika/basic/config/ReaderDirection.dart';
import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart';
import 'package:pikapika/basic/Method.dart';
import 'components/ContentError.dart';
import 'components/ContentLoading.dart';
import 'components/ImageReader.dart';
//
@ -143,43 +145,78 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
return readerKeyboardHolder(_build(context));
}
Future _onSelectDirection() async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
}
Future _onSelectReaderType() async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
}
Widget _build(BuildContext context) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: () async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
},
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: () async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
},
icon: Icon(Icons.view_day_outlined),
),
],
return FutureBuilder(
future: _future,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasError) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentError(
error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async {
setState(() {
_future = _load();
});
},
),
body: ContentBuilder(
future: _future,
onRefresh: () async {
setState(() {
_future = _load();
});
},
successBuilder:
(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return ImageReader(
);
}
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentLoading(label: '加载中'),
);
}
var epNameMap = Map<int, String>();
widget.epList.forEach((element) {
epNameMap[element.epOrder] = element.title;
});
return Scaffold(
body: ImageReader(
ImageReaderStruct(
images: pictures
.map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath,
@ -194,10 +231,15 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
initPosition: widget.initPicturePosition,
pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection,
epOrder: _ep.epOrder,
epNameMap: epNameMap,
comicTitle: widget.comicInfo.title,
onSelectDirection: _onSelectDirection,
onSelectReaderType: _onSelectReaderType,
),
);
},
),
),
);
},
);
}

View File

@ -146,19 +146,21 @@ class _ComicInfoCard extends State<ComicInfoCard> {
iconMargin,
]
: []),
info.epsCount > 0
? Row(
children: [
iconPage,
iconSpacing,
Text(
...(info.epsCount > 0
? [
Text.rich(TextSpan(children: [
WidgetSpan(child: iconPage),
WidgetSpan(child: iconSpacing),
WidgetSpan(child: Text(
"${info.epsCount}E / ${info.pagesCount}P",
style: countLabelStyle,
strutStyle: iconLabelStrutStyle,
),
],
)
: Container(),
softWrap: false,
)),
WidgetSpan(child: iconMargin),
])),
]
: []),
iconMargin,
],
),

View File

@ -113,6 +113,11 @@ class ImageReaderStruct {
final int? initPosition;
final ReaderType pagerType;
final ReaderDirection pagerDirection;
final Map<int, String> epNameMap;
final int epOrder;
final String comicTitle;
final FutureOr<dynamic> Function() onSelectDirection;
final FutureOr<dynamic> Function() onSelectReaderType;
const ImageReaderStruct({
required this.images,
@ -125,6 +130,11 @@ class ImageReaderStruct {
this.initPosition,
required this.pagerType,
required this.pagerDirection,
required this.epNameMap,
required this.epOrder,
required this.comicTitle,
required this.onSelectDirection,
required this.onSelectReaderType,
});
}
@ -170,16 +180,6 @@ abstract class _ImageReaderState extends State<ImageReader> {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
_buildViewer(),
_buildControllerAndBar(),
],
);
}
void _onPageControl(_ReaderControllerEventArgs? args) {
if (args != null) {
var event = args.key;
@ -223,123 +223,153 @@ abstract class _ImageReaderState extends State<ImageReader> {
}
}
Widget _buildControllerAndBar() {
if (widget.struct.fullScreen) {
return _buildController();
}
return SafeArea(
child: Column(
children: [
Expanded(
child: _buildController(hiddenFullScreen: true),
),
Container(
color: readerAppbarColor2,
child: Row(
children: [
Container(width: 15),
IconButton(
icon: Icon(Icons.fullscreen),
color: Colors.white,
onPressed: () {
widget.struct.onFullScreenChange(!widget.struct.fullScreen);
},
),
Container(width: 10),
Expanded(
child: Column(
children: [
Container(height: 3),
Container(
height: 25,
child: FlutterSlider(
axis: Axis.horizontal,
values: [_slider.toDouble()],
min: 0,
max: widget.struct.images.length.toDouble(),
onDragging: (handlerIndex, lowerValue, upperValue) {
_slider = (lowerValue.toInt());
},
onDragCompleted:
(handlerIndex, lowerValue, upperValue) {
_slider = (lowerValue.toInt());
if (_slider != _current) {
_needJumpTo(_slider, false);
}
},
trackBar: FlutterSliderTrackBar(
inactiveTrackBar: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey.shade300,
),
activeTrackBar: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: Theme.of(context).colorScheme.secondary,
),
),
step: FlutterSliderStep(
step: 1,
isPercentRange: false,
),
tooltip: FlutterSliderTooltip(custom: (value) {
double a = value + 1;
return Container(
padding: EdgeInsets.all(8),
decoration: ShapeDecoration(
color: Colors.black.withAlpha(0xCC),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadiusDirectional.circular(3)),
),
child: Text(
'${a.toInt()}',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
);
}),
),
),
Container(height: 3),
],
),
),
Container(width: 10),
IconButton(
icon: Icon(Icons.skip_next_outlined),
color: Colors.white,
onPressed: () {
widget.struct.onNextAction();
},
),
Container(width: 15),
],
),
),
],
),
);
}
Widget _buildController({bool hiddenFullScreen = false}) {
@override
Widget build(BuildContext context) {
switch (currentFullScreenAction()) {
case FullScreenAction.CONTROLLER:
if (hiddenFullScreen) {
return Container();
}
return _buildFullScreenController();
return Stack(
children: [
_buildViewerAndBar(),
_buildFullScreenController(),
],
);
case FullScreenAction.TOUCH_ONCE:
return _buildTouchOnceController();
return _buildTouchOnceController(_buildViewerAndBar());
case FullScreenAction.THREE_AREA:
return _buildThreeAreaController();
return Stack(
children: [
_buildViewerAndBar(),
_buildThreeAreaController(),
],
);
default:
return Container();
}
}
Widget _buildViewerAndBar() {
return Stack(
children: [
_buildViewer(),
widget.struct.fullScreen ? Container() : _buildBar(),
],
);
}
Widget _buildBar() {
return Column(
children: [
AppBar(
title: Text(
"${widget.struct.epNameMap[widget.struct.epOrder] ?? ""} - ${widget.struct.comicTitle}"),
backgroundColor: readerAppbarColor2,
actions: [
IconButton(
onPressed: widget.struct.onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: widget.struct.onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
Expanded(child: Container()),
Container(
height: 45,
color: readerAppbarColor2,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(width: 15),
IconButton(
icon: Icon(Icons.fullscreen),
color: Colors.white,
onPressed: () {
widget.struct.onFullScreenChange(!widget.struct.fullScreen);
},
),
Container(width: 10),
Expanded(
child: Column(
children: [
Expanded(child: Container()),
Container(
height: 25,
child: FlutterSlider(
axis: Axis.horizontal,
values: [_slider.toDouble()],
min: 0,
max: widget.struct.images.length.toDouble(),
onDragging: (handlerIndex, lowerValue, upperValue) {
_slider = (lowerValue.toInt());
},
onDragCompleted:
(handlerIndex, lowerValue, upperValue) {
_slider = (lowerValue.toInt());
if (_slider != _current) {
_needJumpTo(_slider, false);
}
},
trackBar: FlutterSliderTrackBar(
inactiveTrackBar: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey.shade300,
),
activeTrackBar: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: Theme.of(context).colorScheme.secondary,
),
),
step: FlutterSliderStep(
step: 1,
isPercentRange: false,
),
tooltip: FlutterSliderTooltip(custom: (value) {
double a = value + 1;
return Container(
padding: EdgeInsets.all(8),
decoration: ShapeDecoration(
color: Colors.black.withAlpha(0xCC),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadiusDirectional.circular(3)),
),
child: Text(
'${a.toInt()}',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
);
}),
),
),
Expanded(child: Container()),
],
),
),
Container(width: 10),
IconButton(
icon: Icon(Icons.skip_next_outlined),
color: Colors.white,
onPressed: () {
widget.struct.onNextAction();
},
),
Container(width: 15),
],
),
)
],
);
}
Widget _buildFullScreenController() {
if (!widget.struct.fullScreen) {
return Container();
}
return Align(
alignment: Alignment.bottomLeft,
child: Material(
@ -371,13 +401,13 @@ abstract class _ImageReaderState extends State<ImageReader> {
);
}
Widget _buildTouchOnceController() {
Widget _buildTouchOnceController(Widget viewerAndBar) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
widget.struct.onFullScreenChange(!widget.struct.fullScreen);
},
child: Container(),
child: viewerAndBar,
);
}
@ -582,13 +612,13 @@ class _WebToonReaderState extends _ImageReaderState {
reverse:
widget.struct.pagerDirection == ReaderDirection.RIGHT_TO_LEFT,
padding: EdgeInsets.only(
top: widget.struct.fullScreen ? (scaffold.appBarMaxHeight ?? 0) : 0,
top: (scaffold.appBarMaxHeight ?? 0),
bottom:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? 130
: (widget.struct.fullScreen
? (scaffold.appBarMaxHeight ?? 0)
: 0),
: 45),
),
itemScrollController: _itemScrollController,
itemPositionsListener: _itemPositionsListener,
@ -759,8 +789,8 @@ class _GalleryReaderState extends _ImageReaderState {
@override
void initState() {
_pageController = PageController(initialPage: super._startIndex);
super.initState();
_pageController = PageController(initialPage: super._startIndex);
}
@override
@ -792,7 +822,7 @@ class _GalleryReaderState extends _ImageReaderState {
}
Widget _buildViewer() {
var gallery = PhotoViewGallery.builder(
Widget gallery = PhotoViewGallery.builder(
scrollDirection:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? Axis.vertical
@ -838,7 +868,7 @@ class _GalleryReaderState extends _ImageReaderState {
);
},
);
return GestureDetector(
gallery = GestureDetector(
child: gallery,
onLongPress: () async {
if (_current >= 0 && _current < widget.struct.images.length) {
@ -875,10 +905,15 @@ class _GalleryReaderState extends _ImageReaderState {
}
},
);
}
Widget _buildNextEpButton() {
return Container();
var scaffold = Scaffold.of(context);
gallery = Container(
padding: EdgeInsets.only(
top: widget.struct.fullScreen ? 0 : (scaffold.appBarMaxHeight ?? 0),
bottom: widget.struct.fullScreen ? 0 : 45,
),
child: gallery,
);
return gallery;
}
}