🐛 Regression: page state is not saved
- Dominant language
- Dart
- Stars
- 3.5k
- Forks
- 506
- Avg merge
- 11d 2h
- Merged PRs (30d)
- 3
Description
**Describe the bug**
Prior to 4.14, I've been successfully using `AutomaticKeepAliveClientMixin` to keep state widgets alive between page changes in a `NavigationView`. With 4.14 that behavior broke, and changing pages (panes) in a navigation view now disposes and reinitializes the corresponding state widget every time.
**To Reproduce**
Steps to reproduce the behavior:
```dart
import 'dart:math';
import 'package:fluent_ui/fluent_ui.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State createState() => _MainApp();
}
class _MainApp extends State {
int index = 0;
@override
Widget build(BuildContext context) {
return FluentApp(
home: NavigationView(
pane: NavigationPane(
selected: index,
onChanged: (index) => setState(() => this.index = index),
items: [
PaneItem(
icon: Icon(FluentIcons.home),
title: Text('Home'),
body: Center(child: Text('Home Page')),
),
PaneItem(
icon: Icon(FluentIcons.settings),
title: Text('Settings'),
body: SettingsPage(),
),
],
),
),
);
}
}
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@override
State createState() => _SettingsPageState();
}
class _SettingsPageState extends State
with AutomaticKeepAliveClientMixin {
int _counter = 0;
@override
void initState() {
super.initState();
_counter = Random().nextInt(100);
}
@override
Widget build(BuildContext context) {
super.build(context);
return Center(child: Text('Counter: $_counter'));
}
@override
bool get wantKeepAlive => true;
}
```
**With fluent_ui 4.14:** Switching between the two pages causes a different number to be displayed each time.
**With fluent_ui 4.13:** The same number is displayed every time.
**Expected behavior**
The state is maintained.
**Screenshots**
n/a
**Additional context**
n/a
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the supplied Dart reproduction with fluent_ui 4.14 and compare its NavigationView, NavigationPane, and AutomaticKeepAliveClientMixin behavior with 4.13. Trace the page-switching implementation and add or update regression coverage so a stateful pane retains its state when navigating away and back.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100