mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-14 01:44:17 +08:00
Fix bug
This commit is contained in:
1
lib/platform/replace_current_route.dart
Normal file
1
lib/platform/replace_current_route.dart
Normal file
@@ -0,0 +1 @@
|
||||
export 'replace_current_route_none.dart' if (dart.library.html) 'replace_current_route_web.dart';
|
||||
3
lib/platform/replace_current_route_none.dart
Normal file
3
lib/platform/replace_current_route_none.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
void replaceCurrentRoute(String query) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
13
lib/platform/replace_current_route_web.dart
Normal file
13
lib/platform/replace_current_route_web.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// ignore: avoid_web_libraries_in_flutter
|
||||
import 'dart:html';
|
||||
|
||||
void replaceCurrentRoute(String query) {
|
||||
const usePathUrl = bool.fromEnvironment("usePathUrl");
|
||||
if (usePathUrl) {
|
||||
final q = query.substring(1);
|
||||
final base = document.baseUri ?? "/";
|
||||
window.history.replaceState(null, "", "$base$q");
|
||||
} else {
|
||||
window.history.replaceState(null, "", "#$query");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio_image_provider/dio_image_provider.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -12,6 +13,7 @@ import 'package:photo_view/photo_view_gallery.dart';
|
||||
import '../api/file.dart';
|
||||
import '../api/gallery.dart';
|
||||
import '../globals.dart';
|
||||
import '../platform/replace_current_route.dart';
|
||||
|
||||
final _log = Logger("SinglePageViewer");
|
||||
|
||||
@@ -84,6 +86,7 @@ class _SinglePageViewer extends State<SinglePageViewer> with ThemeModeWidget {
|
||||
}
|
||||
setState(() {
|
||||
_files = fileData;
|
||||
_error = null;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
@@ -99,9 +102,15 @@ class _SinglePageViewer extends State<SinglePageViewer> with ThemeModeWidget {
|
||||
}
|
||||
|
||||
void _onPageChanged(BuildContext context) {
|
||||
context.replace("/gallery/${widget.gid}/page/${_index + 1}",
|
||||
GoRouter.optionURLReflectsImperativeAPIs = false;
|
||||
final q = "/gallery/${widget.gid}/page/${_index + 1}";
|
||||
context.replace(q,
|
||||
extra: SinglePageViewerExtra(data: _data, files: _files));
|
||||
GoRouter.optionURLReflectsImperativeAPIs = true;
|
||||
_page_changed = false;
|
||||
if (kIsWeb) {
|
||||
replaceCurrentRoute(q);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -152,7 +161,6 @@ class _SinglePageViewer extends State<SinglePageViewer> with ThemeModeWidget {
|
||||
bindings: [
|
||||
KeyAction(LogicalKeyboardKey.arrowLeft, "previous page", () {
|
||||
if (_index > 0) {
|
||||
_index -= 1;
|
||||
_pageController.previousPage(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut);
|
||||
@@ -160,7 +168,6 @@ class _SinglePageViewer extends State<SinglePageViewer> with ThemeModeWidget {
|
||||
}),
|
||||
KeyAction(LogicalKeyboardKey.arrowRight, "next page", () {
|
||||
if (_index < _data!.pages.length - 1) {
|
||||
_index += 1;
|
||||
_pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut);
|
||||
|
||||
Reference in New Issue
Block a user