Kate Lovett 9d96df2364
Modernize framework lints (#179089)
WIP

Commits separated as follows:
- Update lints in analysis_options files
- Run `dart fix --apply`
- Clean up leftover analysis issues 
- Run `dart format .` in the right places.

Local analysis and testing passes. Checking CI now.

Part of https://github.com/flutter/flutter/issues/178827
- Adoption of flutter_lints in examples/api coming in a separate change
(cc @loic-sharma)

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-11-26 01:10:39 +00:00

195 lines
7.5 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('awaiting animation controllers - using direct future', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller1.dispose);
final controller2 = AnimationController(
duration: const Duration(milliseconds: 600),
vsync: const TestVSync(),
);
addTearDown(controller2.dispose);
final controller3 = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: const TestVSync(),
);
addTearDown(controller3.dispose);
final log = <String>[];
Future<void> runTest() async {
log.add('a'); // t=0
await controller1.forward(); // starts at t=0 again
log.add('b'); // wants to end at t=100 but missed frames until t=150
await controller2.forward(); // starts at t=150
log.add('c'); // wants to end at t=750 but missed frames until t=799
await controller3.forward(); // starts at t=799
log.add('d'); // wants to end at t=1099 but missed frames until t=1200
}
log.add('start');
runTest().then((void value) {
log.add('end');
});
await tester.pump(); // t=0
expect(log, <String>['start', 'a']);
await tester.pump(); // t=0 again
expect(log, <String>['start', 'a']);
await tester.pump(const Duration(milliseconds: 50)); // t=50
expect(log, <String>['start', 'a']);
await tester.pump(const Duration(milliseconds: 100)); // t=150
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 50)); // t=200
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 400)); // t=600
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 199)); // t=799
expect(log, <String>['start', 'a', 'b', 'c']);
await tester.pump(const Duration(milliseconds: 51)); // t=850
expect(log, <String>['start', 'a', 'b', 'c']);
await tester.pump(const Duration(milliseconds: 400)); // t=1200
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
await tester.pump(const Duration(milliseconds: 400)); // t=1600
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
});
testWidgets('awaiting animation controllers - using orCancel', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller1.dispose);
final controller2 = AnimationController(
duration: const Duration(milliseconds: 600),
vsync: const TestVSync(),
);
addTearDown(controller2.dispose);
final controller3 = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: const TestVSync(),
);
addTearDown(controller3.dispose);
final log = <String>[];
Future<void> runTest() async {
log.add('a'); // t=0
await controller1.forward().orCancel; // starts at t=0 again
log.add('b'); // wants to end at t=100 but missed frames until t=150
await controller2.forward().orCancel; // starts at t=150
log.add('c'); // wants to end at t=750 but missed frames until t=799
await controller3.forward().orCancel; // starts at t=799
log.add('d'); // wants to end at t=1099 but missed frames until t=1200
}
log.add('start');
runTest().then((void value) {
log.add('end');
});
await tester.pump(); // t=0
expect(log, <String>['start', 'a']);
await tester.pump(); // t=0 again
expect(log, <String>['start', 'a']);
await tester.pump(const Duration(milliseconds: 50)); // t=50
expect(log, <String>['start', 'a']);
await tester.pump(const Duration(milliseconds: 100)); // t=150
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 50)); // t=200
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 400)); // t=600
expect(log, <String>['start', 'a', 'b']);
await tester.pump(const Duration(milliseconds: 199)); // t=799
expect(log, <String>['start', 'a', 'b', 'c']);
await tester.pump(const Duration(milliseconds: 51)); // t=850
expect(log, <String>['start', 'a', 'b', 'c']);
await tester.pump(const Duration(milliseconds: 400)); // t=1200
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
await tester.pump(const Duration(milliseconds: 400)); // t=1600
expect(log, <String>['start', 'a', 'b', 'c', 'd', 'end']);
});
testWidgets('awaiting animation controllers and failing', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
final log = <String>[];
Future<void> runTest() async {
try {
log.add('start');
await controller1.forward().orCancel;
log.add('fail');
} on TickerCanceled {
log.add('caught');
}
}
runTest().then((void value) {
log.add('end');
});
await tester.pump(); // start ticker
expect(log, <String>['start']);
await tester.pump(const Duration(milliseconds: 50));
expect(log, <String>['start']);
controller1.dispose();
expect(log, <String>['start']);
await tester.idle();
expect(log, <String>['start', 'caught', 'end']);
});
testWidgets('creating orCancel future later', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller1.dispose);
final TickerFuture f = controller1.forward();
await tester.pump(); // start ticker
await tester.pump(const Duration(milliseconds: 200)); // end ticker
await f; // should be a no-op
await f.orCancel; // should create a resolved future
expect(true, isTrue); // should reach here
});
testWidgets('creating orCancel future later', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller1.dispose);
final TickerFuture f = controller1.forward();
await tester.pump(); // start ticker
controller1.stop(); // cancel ticker
var ok = false;
try {
await f.orCancel; // should create a resolved future
} on TickerCanceled {
ok = true;
}
expect(ok, isTrue); // should reach here
});
testWidgets('TickerFuture is a Future', (WidgetTester tester) async {
final controller1 = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller1.dispose);
final TickerFuture f = controller1.forward();
await tester.pump(); // start ticker
await tester.pump(const Duration(milliseconds: 200)); // end ticker
expect(f.asStream().single, isA<Future<void>>());
await f.catchError((dynamic e) {
throw 'do not reach';
});
expect(await f.then<bool>((_) => true), isTrue);
expect(f.whenComplete(() => false), isA<Future<void>>());
expect(f.timeout(const Duration(seconds: 5)), isA<Future<void>>());
});
}