@@ -91,7 +91,7 @@ void main() {
91
91
});
92
92
93
93
testWidgets (
94
- 'Navigation Rail index should update when icon button is pressed' ,
94
+ 'navRailIndexStateProvider should update when icon button is pressed' ,
95
95
(tester) async {
96
96
await tester.pumpWidget (
97
97
const ProviderScope (
@@ -111,7 +111,8 @@ void main() {
111
111
expect (container.read (navRailIndexStateProvider), 1 );
112
112
});
113
113
114
- testWidgets ('Navigation Rail index should persist across widget rebuilds' ,
114
+ testWidgets (
115
+ 'navRailIndexStateProvider should persist across widget rebuilds' ,
115
116
(tester) async {
116
117
// Pump the initial widget tree
117
118
await tester.pumpWidget (
@@ -146,7 +147,8 @@ void main() {
146
147
expect (find.byType (HomePage ), findsNothing);
147
148
});
148
149
149
- testWidgets ('UI should update correctly when Navigation Rail index changes' ,
150
+ testWidgets (
151
+ 'UI should update correctly when navRailIndexStateProvider changes' ,
150
152
(tester) async {
151
153
await tester.pumpWidget (
152
154
const ProviderScope (
@@ -178,5 +180,38 @@ void main() {
178
180
// Verify that the selected icon is the filled version (selectedIcon)
179
181
expect (find.byIcon (Icons .settings), findsOneWidget);
180
182
});
183
+
184
+ testWidgets (
185
+ 'navRailIndexStateProvider should be disposed when Dashboard is removed' ,
186
+ (tester) async {
187
+ await tester.pumpWidget (
188
+ const ProviderScope (
189
+ child: MaterialApp (
190
+ home: Dashboard (),
191
+ ),
192
+ ),
193
+ );
194
+
195
+ // Grab the Dashboard widget and its ProviderContainer
196
+ final dashboard = tester.element (find.byType (Dashboard ));
197
+ final container = ProviderScope .containerOf (dashboard);
198
+
199
+ // Pumping a different widget to remove the Dashboard from the widget tree
200
+ await tester.pumpWidget (
201
+ const MaterialApp (
202
+ home: Scaffold (body: Text ('Different Widget' )),
203
+ ),
204
+ );
205
+
206
+ // Verify that the ProviderContainer has been disposed
207
+ // by trying to read from disposed container
208
+ bool isDisposed = false ;
209
+ try {
210
+ container.read (navRailIndexStateProvider);
211
+ } catch (e) {
212
+ isDisposed = true ;
213
+ }
214
+ expect (isDisposed, true );
215
+ });
181
216
});
182
217
}
0 commit comments