fix: Fix PageView not working after adding an entry

This commit is contained in:
2026-07-26 21:59:51 +02:00
parent 3a6ab1e825
commit 437d76fddc
2 changed files with 7 additions and 19 deletions

View File

@@ -6,7 +6,6 @@ import 'package:anitrack/src/ui/bloc/navigation_bloc.dart';
import 'package:anitrack/src/ui/constants.dart'; import 'package:anitrack/src/ui/constants.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/cupertino.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
@@ -42,9 +41,6 @@ class AnimeListBloc extends Bloc<AnimeListEvent, AnimeListState> {
growable: true, growable: true,
); );
/// Controller for the bottom navigation bar
final pageController = PageController();
List<AnimeTrackingData> get unfilteredAnime => _animes; List<AnimeTrackingData> get unfilteredAnime => _animes;
List<AnimeTrackingData> _getFilteredAnime({ List<AnimeTrackingData> _getFilteredAnime({

View File

@@ -10,7 +10,6 @@ import 'package:bottom_bar/bottom_bar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
class AnimeListPage extends StatefulWidget { class AnimeListPage extends StatefulWidget {
const AnimeListPage({ const AnimeListPage({
@@ -104,17 +103,15 @@ class AnimeListPage extends StatefulWidget {
AnimeListPage.getPageTitle(state.trackingType), AnimeListPage.getPageTitle(state.trackingType),
), ),
), ),
actions: [ actions: const [
BlocBuilder<AnimeListBloc, AnimeListState>( BlocBuilder<AnimeListBloc, AnimeListState>(
builder: (context, state) => builder: AnimeListPage.getPopupButton,
AnimeListPage.getPopupButton(context, state),
), ),
], ],
); );
} }
static Widget buildBottomNavigationBar(BuildContext context) { static Widget buildBottomNavigationBar(BuildContext context) {
final pageController = context.read<AnimeListBloc>().pageController;
return BlocBuilder<AnimeListBloc, AnimeListState>( return BlocBuilder<AnimeListBloc, AnimeListState>(
builder: (context, state) => BottomBar( builder: (context, state) => BottomBar(
selectedIndex: state.trackingType == TrackingMediumType.anime ? 0 : 1, selectedIndex: state.trackingType == TrackingMediumType.anime ? 0 : 1,
@@ -124,8 +121,6 @@ class AnimeListPage extends StatefulWidget {
index == 0 ? TrackingMediumType.anime : TrackingMediumType.manga, index == 0 ? TrackingMediumType.anime : TrackingMediumType.manga,
), ),
); );
pageController.jumpToPage(index);
}, },
items: [ items: [
BottomBarItem( BottomBarItem(
@@ -155,7 +150,9 @@ class AnimeListPage extends StatefulWidget {
curve: Curves.easeInOutQuint, curve: Curves.easeInOutQuint,
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () { onPressed: () {
context.push(animeSearchRoute); context.read<AnimeSearchBloc>().add(
AnimeSearchRequestedEvent(state.trackingType),
);
}, },
tooltip: t.tooltips.addNewItem, tooltip: t.tooltips.addNewItem,
child: const Icon(Icons.add), child: const Icon(Icons.add),
@@ -170,7 +167,6 @@ class AnimeListPage extends StatefulWidget {
} }
class AnimeListPageState extends State<AnimeListPage> { class AnimeListPageState extends State<AnimeListPage> {
final PageController _controller = PageController();
final ScrollController _animeScrollController = ScrollController(); final ScrollController _animeScrollController = ScrollController();
@override @override
@@ -180,7 +176,6 @@ class AnimeListPageState extends State<AnimeListPage> {
} }
void _onAnimeListScrolled() { void _onAnimeListScrolled() {
//print(_animeScrollController.position.maxScrollExtent);
final bloc = GetIt.I.get<AnimeListBloc>(); final bloc = GetIt.I.get<AnimeListBloc>();
if (_animeScrollController.offset + 20 >= if (_animeScrollController.offset + 20 >=
_animeScrollController.position.maxScrollExtent) { _animeScrollController.position.maxScrollExtent) {
@@ -202,11 +197,8 @@ class AnimeListPageState extends State<AnimeListPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<AnimeListBloc, AnimeListState>( return BlocBuilder<AnimeListBloc, AnimeListState>(
builder: (context, state) { builder: (context, state) {
return PageView( return IndexedStack(
// Prevent swiping between pages index: state.trackingType == TrackingMediumType.anime ? 0 : 1,
// (https://github.com/flutter/flutter/issues/37510#issuecomment-612663656)
physics: const NeverScrollableScrollPhysics(),
controller: _controller,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),