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/ReaderDirection.dart';
import 'package:pikapika/basic/config/ReaderType.dart'; import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/basic/const.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'; import 'components/ImageReader.dart';
// 线 // 线
@ -151,55 +152,92 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
return readerKeyboardHolder(_build(context)); 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) { Widget _build(BuildContext context) {
return Scaffold( return FutureBuilder(
appBar: _fullScreen future: _future,
? null builder: (BuildContext context,
: AppBar( AsyncSnapshot<List<RemoteImageInfo>> snapshot) {
backgroundColor: readerAppbarColor, if (snapshot.hasError) {
title: Text("${_ep.title} - ${widget.comicInfo.title}"), return Scaffold(
actions: [ appBar: _fullScreen
IconButton( ? null
onPressed: () async { : AppBar(
await choosePagerDirection(context); backgroundColor: readerAppbarColor,
if (widget.pagerDirection != gReaderDirection) { title: Text("${_ep.title} - ${widget.comicInfo.title}"),
_reloadReader(); actions: [
} IconButton(
}, onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio), icon: Icon(Icons.grid_goldenratio),
), ),
IconButton( IconButton(
onPressed: () async { onPressed: _onSelectReaderType,
await choosePagerType(context); icon: Icon(Icons.view_day_outlined),
if (widget.pagerType != currentReaderType()) { ),
_reloadReader(); ],
} ),
}, body: ContentError(
icon: Icon(Icons.view_day_outlined), error: snapshot.error,
), stackTrace: snapshot.stackTrace,
], onRefresh: () async {
setState(() {
_future = _load();
});
},
), ),
body: ContentBuilder( );
future: _future, }
onRefresh: () async { if (snapshot.connectionState != ConnectionState.done) {
setState(() { return Scaffold(
_future = _load(); appBar: _fullScreen
}); ? null
}, : AppBar(
successBuilder: (BuildContext context, backgroundColor: readerAppbarColor,
AsyncSnapshot<List<RemoteImageInfo>> snapshot) { title: Text("${_ep.title} - ${widget.comicInfo.title}"),
return ImageReader( 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( ImageReaderStruct(
images: snapshot.data! images: snapshot.data!
.map((e) => ReaderImageInfo( .map((e) => ReaderImageInfo(
e.fileServer, e.fileServer,
e.path, e.path,
null, null,
null, null,
null, null,
null, null,
null, null,
)) ))
.toList(), .toList(),
fullScreen: _fullScreen, fullScreen: _fullScreen,
onFullScreenChange: _onFullScreenChange, onFullScreenChange: _onFullScreenChange,
@ -210,10 +248,15 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
initPosition: widget.initPicturePosition, initPosition: widget.initPicturePosition,
pagerType: widget.pagerType, pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection, 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/basic/config/ReaderType.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart'; import 'package:pikapika/screens/components/ContentBuilder.dart';
import 'package:pikapika/basic/Method.dart'; import 'package:pikapika/basic/Method.dart';
import 'components/ContentError.dart';
import 'components/ContentLoading.dart';
import 'components/ImageReader.dart'; import 'components/ImageReader.dart';
// //
@ -143,43 +145,78 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
return readerKeyboardHolder(_build(context)); 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) { Widget _build(BuildContext context) {
return Scaffold( return FutureBuilder(
appBar: _fullScreen future: _future,
? null builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
: AppBar( if (snapshot.hasError) {
title: Text("${_ep.title} - ${widget.comicInfo.title}"), return Scaffold(
actions: [ appBar: _fullScreen
IconButton( ? null
onPressed: () async { : AppBar(
await choosePagerDirection(context); title: Text("${_ep.title} - ${widget.comicInfo.title}"),
if (widget.pagerDirection != gReaderDirection) { actions: [
_reloadReader(); IconButton(
} onPressed: _onSelectDirection,
}, icon: Icon(Icons.grid_goldenratio),
icon: Icon(Icons.grid_goldenratio), ),
), IconButton(
IconButton( onPressed: _onSelectReaderType,
onPressed: () async { icon: Icon(Icons.view_day_outlined),
await choosePagerType(context); ),
if (widget.pagerType != currentReaderType()) { ],
_reloadReader(); ),
} body: ContentError(
}, error: snapshot.error,
icon: Icon(Icons.view_day_outlined), stackTrace: snapshot.stackTrace,
), onRefresh: () async {
], setState(() {
_future = _load();
});
},
), ),
body: ContentBuilder( );
future: _future, }
onRefresh: () async { if (snapshot.connectionState != ConnectionState.done) {
setState(() { return Scaffold(
_future = _load(); appBar: _fullScreen
}); ? null
}, : AppBar(
successBuilder: title: Text("${_ep.title} - ${widget.comicInfo.title}"),
(BuildContext context, AsyncSnapshot<dynamic> snapshot) { actions: [
return ImageReader( 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( ImageReaderStruct(
images: pictures images: pictures
.map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath, .map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath,
@ -194,10 +231,15 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
initPosition: widget.initPicturePosition, initPosition: widget.initPicturePosition,
pagerType: widget.pagerType, pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection, 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, iconMargin,
] ]
: []), : []),
info.epsCount > 0 ...(info.epsCount > 0
? Row( ? [
children: [ Text.rich(TextSpan(children: [
iconPage, WidgetSpan(child: iconPage),
iconSpacing, WidgetSpan(child: iconSpacing),
Text( WidgetSpan(child: Text(
"${info.epsCount}E / ${info.pagesCount}P", "${info.epsCount}E / ${info.pagesCount}P",
style: countLabelStyle, style: countLabelStyle,
strutStyle: iconLabelStrutStyle, strutStyle: iconLabelStrutStyle,
), softWrap: false,
], )),
) WidgetSpan(child: iconMargin),
: Container(), ])),
]
: []),
iconMargin, iconMargin,
], ],
), ),

View File

@ -113,6 +113,11 @@ class ImageReaderStruct {
final int? initPosition; final int? initPosition;
final ReaderType pagerType; final ReaderType pagerType;
final ReaderDirection pagerDirection; 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({ const ImageReaderStruct({
required this.images, required this.images,
@ -125,6 +130,11 @@ class ImageReaderStruct {
this.initPosition, this.initPosition,
required this.pagerType, required this.pagerType,
required this.pagerDirection, 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(); super.dispose();
} }
@override
Widget build(BuildContext context) {
return Stack(
children: [
_buildViewer(),
_buildControllerAndBar(),
],
);
}
void _onPageControl(_ReaderControllerEventArgs? args) { void _onPageControl(_ReaderControllerEventArgs? args) {
if (args != null) { if (args != null) {
var event = args.key; var event = args.key;
@ -223,123 +223,153 @@ abstract class _ImageReaderState extends State<ImageReader> {
} }
} }
Widget _buildControllerAndBar() { @override
if (widget.struct.fullScreen) { Widget build(BuildContext context) {
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}) {
switch (currentFullScreenAction()) { switch (currentFullScreenAction()) {
case FullScreenAction.CONTROLLER: case FullScreenAction.CONTROLLER:
if (hiddenFullScreen) { return Stack(
return Container(); children: [
} _buildViewerAndBar(),
return _buildFullScreenController(); _buildFullScreenController(),
],
);
case FullScreenAction.TOUCH_ONCE: case FullScreenAction.TOUCH_ONCE:
return _buildTouchOnceController(); return _buildTouchOnceController(_buildViewerAndBar());
case FullScreenAction.THREE_AREA: case FullScreenAction.THREE_AREA:
return _buildThreeAreaController(); return Stack(
children: [
_buildViewerAndBar(),
_buildThreeAreaController(),
],
);
default: default:
return Container(); 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() { Widget _buildFullScreenController() {
if (!widget.struct.fullScreen) {
return Container();
}
return Align( return Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: Material( child: Material(
@ -371,13 +401,13 @@ abstract class _ImageReaderState extends State<ImageReader> {
); );
} }
Widget _buildTouchOnceController() { Widget _buildTouchOnceController(Widget viewerAndBar) {
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
widget.struct.onFullScreenChange(!widget.struct.fullScreen); widget.struct.onFullScreenChange(!widget.struct.fullScreen);
}, },
child: Container(), child: viewerAndBar,
); );
} }
@ -582,13 +612,13 @@ class _WebToonReaderState extends _ImageReaderState {
reverse: reverse:
widget.struct.pagerDirection == ReaderDirection.RIGHT_TO_LEFT, widget.struct.pagerDirection == ReaderDirection.RIGHT_TO_LEFT,
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: widget.struct.fullScreen ? (scaffold.appBarMaxHeight ?? 0) : 0, top: (scaffold.appBarMaxHeight ?? 0),
bottom: bottom:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? 130 ? 130
: (widget.struct.fullScreen : (widget.struct.fullScreen
? (scaffold.appBarMaxHeight ?? 0) ? (scaffold.appBarMaxHeight ?? 0)
: 0), : 45),
), ),
itemScrollController: _itemScrollController, itemScrollController: _itemScrollController,
itemPositionsListener: _itemPositionsListener, itemPositionsListener: _itemPositionsListener,
@ -759,8 +789,8 @@ class _GalleryReaderState extends _ImageReaderState {
@override @override
void initState() { void initState() {
_pageController = PageController(initialPage: super._startIndex);
super.initState(); super.initState();
_pageController = PageController(initialPage: super._startIndex);
} }
@override @override
@ -792,7 +822,7 @@ class _GalleryReaderState extends _ImageReaderState {
} }
Widget _buildViewer() { Widget _buildViewer() {
var gallery = PhotoViewGallery.builder( Widget gallery = PhotoViewGallery.builder(
scrollDirection: scrollDirection:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? Axis.vertical ? Axis.vertical
@ -838,7 +868,7 @@ class _GalleryReaderState extends _ImageReaderState {
); );
}, },
); );
return GestureDetector( gallery = GestureDetector(
child: gallery, child: gallery,
onLongPress: () async { onLongPress: () async {
if (_current >= 0 && _current < widget.struct.images.length) { if (_current >= 0 && _current < widget.struct.images.length) {
@ -875,10 +905,15 @@ class _GalleryReaderState extends _ImageReaderState {
} }
}, },
); );
} var scaffold = Scaffold.of(context);
gallery = Container(
Widget _buildNextEpButton() { padding: EdgeInsets.only(
return Container(); top: widget.struct.fullScreen ? 0 : (scaffold.appBarMaxHeight ?? 0),
bottom: widget.struct.fullScreen ? 0 : 45,
),
child: gallery,
);
return gallery;
} }
} }