I can't find any answers for my problem. In the code below, everything was perfect if I use a "GestureDetector" with a "Image" instead the Dismissible with the PhotoView. When I run it, it throws the "ancestor is unsafe" error.
My code id for show the pages of a comic. The code line "comic.paginaActual(comic.readProgress.page)" returns a NetworkImage with the comic page. When the user "dismiss" the page (using the dismissible widget), the app loads the next page (at least is the expected result).
As I said, i've tried with a Gesture detector (with horizontal gesture for the swipe) and just "Image" instead Photoview and it worked perfect, but when I use the Dismissible, the app crashes.
This is the code:
// ignore: use_key_in_widget_constructors
class PaginaFull extends StatefulWidget {
@override
State<PaginaFull> createState() => _PaginaFullState();
}
class _PaginaFullState extends State<PaginaFull> {
late PhotoViewScaleStateController scaleController;
DismissDirection dismissDirection = DismissDirection.horizontal;
@override
void didChangeDependencies() {
_enterFullscreen();
scaleController = PhotoViewScaleStateController();
super.didChangeDependencies();
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
_exitFullscreen();
scaleController.dispose();
}
_enterFullscreen() async {
await FullScreen.enterFullScreen(FullScreenMode.EMERSIVE);
}
_exitFullscreen() async {
await FullScreen.exitFullScreen();
}
void paginaSiguiente({required Comic comic}) {
if (comic.readProgress.page < (comic.media.pagesCount)) {
setState(() {
comic.readProgress.page += 1;
});
}
}
void paginaAnterior({required Comic comic}) {
if (comic.readProgress.page > 1) {
setState(() {
comic.readProgress.page -= 1;
});
}
}
@override
Widget build(BuildContext context) {
final Comic comic = ModalRoute.of(context)!.settings.arguments as Comic;
return Scaffold(
appBar: null,
body: Builder(builder: (context) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: Dismissible(
behavior: HitTestBehavior.translucent,
key: Key(comic.readProgress.page.toString()),
direction: dismissDirection,
onDismissed: (DismissDirection direction) {
if (direction == DismissDirection.startToEnd) {
paginaAnterior(comic: comic);
} else {
paginaSiguiente(comic: comic);
}
},
resizeDuration: null,
child: PhotoView(
scaleStateController: scaleController,
filterQuality: FilterQuality.high,
initialScale: PhotoViewComputedScale.contained,
minScale: PhotoViewComputedScale.contained,
gaplessPlayback: true,
enableRotation: false,
imageProvider: comic.paginaActual(comic.readProgress.page),
),
),
);
}),
);
}
}
Perhaps changing the experience with others widgets.... but i'm new in flutter and i don't now know what else i can use.
Thanks in advance for your help!... from CHILE!
Solved!!!
The problem is coming from photo_view package.
In pubspec.yaml remove photo_view from dependecies
dependencies: photo_view: ^0.13.0 Add:
dependency_overrides: photo_view: git: url: https://github.com/bluefireteam/photo_view ref: master
This avoid the problem!!!