Migrate external_ui to null safety (#80640)
This commit is contained in:
parent
4825c639b6
commit
4f2e7987f4
@ -15,7 +15,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
const MyApp({Key key}) : super(key: key);
|
const MyApp({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => MyAppState();
|
State createState() => MyAppState();
|
||||||
@ -27,17 +27,17 @@ enum FrameState { initial, slow, afterSlow, fast, afterFast }
|
|||||||
|
|
||||||
class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
|
||||||
int _widgetBuilds = 0;
|
int _widgetBuilds = 0;
|
||||||
FrameState _state;
|
FrameState _state = FrameState.initial;
|
||||||
String _summary = '';
|
String _summary = '';
|
||||||
IconData _icon;
|
IconData? _icon;
|
||||||
double _flutterFrameRate;
|
double _flutterFrameRate = 0;
|
||||||
|
|
||||||
Future<void> _summarizeStats() async {
|
Future<void> _summarizeStats() async {
|
||||||
final double framesProduced = await channel.invokeMethod('getProducedFrameRate');
|
final double? framesProduced = await channel.invokeMethod('getProducedFrameRate');
|
||||||
final double framesConsumed = await channel.invokeMethod('getConsumedFrameRate');
|
final double? framesConsumed = await channel.invokeMethod('getConsumedFrameRate');
|
||||||
_summary = '''
|
_summary = '''
|
||||||
Produced: ${framesProduced.toStringAsFixed(1)}fps
|
Produced: ${framesProduced?.toStringAsFixed(1)}fps
|
||||||
Consumed: ${framesConsumed.toStringAsFixed(1)}fps
|
Consumed: ${framesConsumed?.toStringAsFixed(1)}fps
|
||||||
Widget builds: $_widgetBuilds''';
|
Widget builds: $_widgetBuilds''';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,15 +96,15 @@ Widget builds: $_widgetBuilds''';
|
|||||||
debugPrint('Awaiting calm (3 second pause)...');
|
debugPrint('Awaiting calm (3 second pause)...');
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 3000));
|
await Future<void>.delayed(const Duration(milliseconds: 3000));
|
||||||
debugPrint('Calibrating...');
|
debugPrint('Calibrating...');
|
||||||
DateTime startTime;
|
late DateTime startTime;
|
||||||
int tickCount = 0;
|
int tickCount = 0;
|
||||||
Ticker ticker;
|
Ticker? ticker;
|
||||||
ticker = createTicker((Duration time) {
|
ticker = createTicker((Duration time) {
|
||||||
tickCount += 1;
|
tickCount += 1;
|
||||||
if (tickCount == calibrationTickCount) { // about 10 seconds
|
if (tickCount == calibrationTickCount) { // about 10 seconds
|
||||||
final Duration elapsed = DateTime.now().difference(startTime);
|
final Duration elapsed = DateTime.now().difference(startTime);
|
||||||
ticker.stop();
|
ticker?.stop();
|
||||||
ticker.dispose();
|
ticker?.dispose();
|
||||||
setState(() {
|
setState(() {
|
||||||
_flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds;
|
_flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds;
|
||||||
debugPrint('Calibrated: frame rate ${_flutterFrameRate.toStringAsFixed(1)}fps.');
|
debugPrint('Calibrated: frame rate ${_flutterFrameRate.toStringAsFixed(1)}fps.');
|
||||||
|
@ -2,7 +2,7 @@ name: external_ui
|
|||||||
description: A test of Flutter integrating external UIs.
|
description: A test of Flutter integrating external UIs.
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
@ -13,7 +13,7 @@ const Duration samplingTime = Duration(seconds: 8);
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
group('texture suite', () {
|
group('texture suite', () {
|
||||||
FlutterDriver driver;
|
late FlutterDriver driver;
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
driver = await FlutterDriver.connect();
|
driver = await FlutterDriver.connect();
|
||||||
@ -32,9 +32,9 @@ Future<void> main() async {
|
|||||||
await driver.waitFor(fab);
|
await driver.waitFor(fab);
|
||||||
|
|
||||||
final String calibrationResult = await driver.getText(summary);
|
final String calibrationResult = await driver.getText(summary);
|
||||||
final Match matchCalibration = calibrationRegExp.matchAsPrefix(calibrationResult);
|
final Match? matchCalibration = calibrationRegExp.matchAsPrefix(calibrationResult);
|
||||||
expect(matchCalibration, isNotNull);
|
expect(matchCalibration, isNotNull);
|
||||||
final double flutterFrameRate = double.parse(matchCalibration.group(1));
|
final double flutterFrameRate = double.parse(matchCalibration?.group(1) ?? '0');
|
||||||
|
|
||||||
// Texture frame stats at 0.5x Flutter frame rate
|
// Texture frame stats at 0.5x Flutter frame rate
|
||||||
await driver.tap(fab);
|
await driver.tap(fab);
|
||||||
@ -42,11 +42,11 @@ Future<void> main() async {
|
|||||||
await driver.tap(fab);
|
await driver.tap(fab);
|
||||||
|
|
||||||
final String statsSlow = await driver.getText(summary);
|
final String statsSlow = await driver.getText(summary);
|
||||||
final Match matchSlow = statsRegExp.matchAsPrefix(statsSlow);
|
final Match matchSlow = statsRegExp.matchAsPrefix(statsSlow)!;
|
||||||
expect(matchSlow, isNotNull);
|
expect(matchSlow, isNotNull);
|
||||||
expect(double.parse(matchSlow.group(1)), closeTo(flutterFrameRate / 2.0, 5.0));
|
expect(double.parse(matchSlow.group(1)!), closeTo(flutterFrameRate / 2.0, 5.0));
|
||||||
expect(double.parse(matchSlow.group(2)), closeTo(flutterFrameRate / 2.0, 5.0));
|
expect(double.parse(matchSlow.group(2)!), closeTo(flutterFrameRate / 2.0, 5.0));
|
||||||
expect(int.parse(matchSlow.group(3)), 1);
|
expect(int.parse(matchSlow.group(3)!), 1);
|
||||||
|
|
||||||
// Texture frame stats at 2.0x Flutter frame rate
|
// Texture frame stats at 2.0x Flutter frame rate
|
||||||
await driver.tap(fab);
|
await driver.tap(fab);
|
||||||
@ -54,15 +54,15 @@ Future<void> main() async {
|
|||||||
await driver.tap(fab);
|
await driver.tap(fab);
|
||||||
|
|
||||||
final String statsFast = await driver.getText(summary);
|
final String statsFast = await driver.getText(summary);
|
||||||
final Match matchFast = statsRegExp.matchAsPrefix(statsFast);
|
final Match matchFast = statsRegExp.matchAsPrefix(statsFast)!;
|
||||||
expect(matchFast, isNotNull);
|
expect(matchFast, isNotNull);
|
||||||
expect(double.parse(matchFast.group(1)), closeTo(flutterFrameRate * 2.0, 5.0));
|
expect(double.parse(matchFast.group(1)!), closeTo(flutterFrameRate * 2.0, 5.0));
|
||||||
expect(double.parse(matchFast.group(2)), closeTo(flutterFrameRate, 10.0));
|
expect(double.parse(matchFast.group(2)!), closeTo(flutterFrameRate, 10.0));
|
||||||
expect(int.parse(matchFast.group(3)), 1);
|
expect(int.parse(matchFast.group(3)!), 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
driver?.close();
|
driver.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user