Reduce Android and iOS background work
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/detail_pages.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'iOS detail polling pauses when hidden and resumes on return',
|
||||
(tester) async {
|
||||
final binding = tester.binding;
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
var builds = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: LiveDetailPage(title: '详情', builder: () => Text('${++builds}')),
|
||||
),
|
||||
);
|
||||
final initial = builds;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(builds, initial + 1);
|
||||
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);
|
||||
final beforeHidden = builds;
|
||||
await tester.pump(const Duration(seconds: 10));
|
||||
expect(builds, beforeHidden);
|
||||
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(builds, beforeHidden + 1);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
variant: const TargetPlatformVariant({TargetPlatform.iOS}),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user