Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate last batch of tests #68163

Merged
merged 1 commit into from Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/rendering/tweens.dart
Expand Up @@ -39,7 +39,7 @@ class FractionalOffsetTween extends Tween<FractionalOffset?> {
///
/// * [AlignmentGeometryTween], which interpolates between two
/// [AlignmentGeometry] objects.
class AlignmentTween extends Tween<Alignment?> {
class AlignmentTween extends Tween<Alignment> {
/// Creates a fractional offset tween.
///
/// The [begin] and [end] properties may be null; the null value
Expand All @@ -49,7 +49,7 @@ class AlignmentTween extends Tween<Alignment?> {

/// Returns the value this variable has at the given animation clock value.
@override
Alignment? lerp(double t) => Alignment.lerp(begin, end, t);
Alignment lerp(double t) => Alignment.lerp(begin, end, t)!;
}

/// An interpolation between two [AlignmentGeometry].
Expand Down
Expand Up @@ -16,7 +16,7 @@ import 'framework.dart';
///
/// * [ValueListenableBuilder], a widget which invokes this builder each time
/// a [ValueListenable] changes value.
typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T? value, Widget? child);
typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, Widget? child);

/// A widget whose content stays synced with a [ValueListenable].
///
Expand Down Expand Up @@ -153,7 +153,7 @@ class ValueListenableBuilder<T> extends StatefulWidget {
}

class _ValueListenableBuilderState<T> extends State<ValueListenableBuilder<T>> {
T? value;
late T value;

@override
void initState() {
Expand Down
34 changes: 16 additions & 18 deletions packages/flutter/test/widgets/transitions_test.dart
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:math' as math;

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -50,7 +48,7 @@ void main() {
),
);

AnimationController controller;
late AnimationController controller;

setUp(() {
controller = AnimationController(vsync: const TestVSync());
Expand All @@ -71,9 +69,9 @@ void main() {
BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration;

expect(actualDecoration.color, const Color(0xFFFFFFFF));
expect(actualDecoration.boxShadow[0].blurRadius, 10.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000));
expect(actualDecoration.boxShadow![0].blurRadius, 10.0);
expect(actualDecoration.boxShadow![0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));

controller.value = 0.5;

Expand All @@ -83,16 +81,16 @@ void main() {

expect(actualDecoration.color, const Color(0xFF7F7F7F));
expect(actualDecoration.border, isA<Border>());
final Border border = actualDecoration.border as Border;
final Border border = actualDecoration.border! as Border;
expect(border.left.width, 2.5);
expect(border.left.style, BorderStyle.solid);
expect(border.left.color, const Color(0xFF101010));
expect(actualDecoration.borderRadius, BorderRadius.circular(5.0));
expect(actualDecoration.shape, BoxShape.rectangle);
expect(actualDecoration.boxShadow[0].blurRadius, 5.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 2.0);
expect(actualDecoration.boxShadow![0].blurRadius, 5.0);
expect(actualDecoration.boxShadow![0].spreadRadius, 2.0);
// Scaling a shadow doesn't change the color.
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000));
expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));

controller.value = 1.0;

Expand Down Expand Up @@ -126,9 +124,9 @@ void main() {
BoxDecoration actualDecoration = actualBox.decoration as BoxDecoration;

expect(actualDecoration.color, const Color(0xFFFFFFFF));
expect(actualDecoration.boxShadow[0].blurRadius, 10.0);
expect(actualDecoration.boxShadow[0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000));
expect(actualDecoration.boxShadow![0].blurRadius, 10.0);
expect(actualDecoration.boxShadow![0].spreadRadius, 4.0);
expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));

controller.value = 0.5;

Expand All @@ -140,16 +138,16 @@ void main() {
// tween's end values given the easeOut curve.
expect(actualDecoration.color, const Color(0xFF505050));
expect(actualDecoration.border, isA<Border>());
final Border border = actualDecoration.border as Border;
final Border border = actualDecoration.border! as Border;
expect(border.left.width, moreOrLessEquals(1.9, epsilon: 0.1));
expect(border.left.style, BorderStyle.solid);
expect(border.left.color, const Color(0xFF151515));
expect(actualDecoration.borderRadius.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1));
expect(actualDecoration.borderRadius!.resolve(TextDirection.ltr).topLeft.x, moreOrLessEquals(6.8, epsilon: 0.1));
expect(actualDecoration.shape, BoxShape.rectangle);
expect(actualDecoration.boxShadow[0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1));
expect(actualDecoration.boxShadow[0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1));
expect(actualDecoration.boxShadow![0].blurRadius, moreOrLessEquals(3.1, epsilon: 0.1));
expect(actualDecoration.boxShadow![0].spreadRadius, moreOrLessEquals(1.2, epsilon: 0.1));
// Scaling a shadow doesn't change the color.
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000));
expect(actualDecoration.boxShadow![0].color, const Color(0x66000000));
});
});

Expand Down
48 changes: 23 additions & 25 deletions packages/flutter/test/widgets/tween_animation_builder_test.dart
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

Expand All @@ -15,7 +13,7 @@ void main() {
TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1),
tween: IntTween(begin: 10, end: 110),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand Down Expand Up @@ -46,7 +44,7 @@ void main() {
TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1),
tween: IntTween(end: 100),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -70,7 +68,7 @@ void main() {
TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1),
tween: IntTween(begin: 100, end: 100),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -88,11 +86,11 @@ void main() {

testWidgets('Replace tween animates new tween', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1),
tween: tween,
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -116,12 +114,12 @@ void main() {

testWidgets('Curve is respected', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween, Curve curve}) {
Widget buildWidget({required IntTween tween, required Curve curve}) {
return TweenAnimationBuilder<int>(
duration: const Duration(seconds: 1),
tween: tween,
curve: curve,
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -146,11 +144,11 @@ void main() {

testWidgets('Duration is respected', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween, Duration duration}) {
Widget buildWidget({required IntTween tween, required Duration duration}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: duration,
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand Down Expand Up @@ -179,8 +177,8 @@ void main() {
child: TweenAnimationBuilder<int>(
tween: IntTween(begin: 0, end: 100),
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
return child;
builder: (BuildContext context, int i, Widget? child) {
return child!;
},
child: const Text('Hello World'),
),
Expand All @@ -193,11 +191,11 @@ void main() {
group('Change tween gapless while', () {
testWidgets('running forward', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand Down Expand Up @@ -228,11 +226,11 @@ void main() {

testWidgets('running forward and then reverse with same tween instance', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -258,11 +256,11 @@ void main() {

testWidgets('Changing tween while gapless tween change is in progress', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand Down Expand Up @@ -298,12 +296,12 @@ void main() {

testWidgets('Changing curve while no animation is running does not trigger animation', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({Curve curve}) {
Widget buildWidget({required Curve curve}) {
return TweenAnimationBuilder<int>(
tween: IntTween(begin: 0, end: 100),
curve: curve,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -327,11 +325,11 @@ void main() {

testWidgets('Setting same tween and direction does not trigger animation', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand All @@ -356,11 +354,11 @@ void main() {

testWidgets('Setting same tween and direction while gapless animation is in progress works', (WidgetTester tester) async {
final List<int> values = <int>[];
Widget buildWidget({IntTween tween}) {
Widget buildWidget({required IntTween tween}) {
return TweenAnimationBuilder<int>(
tween: tween,
duration: const Duration(seconds: 1),
builder: (BuildContext context, int i, Widget child) {
builder: (BuildContext context, int i, Widget? child) {
values.add(i);
return const Placeholder();
},
Expand Down
6 changes: 2 additions & 4 deletions packages/flutter/test/widgets/unique_widget_test.dart
Expand Up @@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

class TestUniqueWidget extends UniqueWidget<TestUniqueWidgetState> {
const TestUniqueWidget({ GlobalKey<TestUniqueWidgetState> key }) : super(key: key);
const TestUniqueWidget({ required GlobalKey<TestUniqueWidgetState> key }) : super(key: key);

@override
TestUniqueWidgetState createState() => TestUniqueWidgetState();
Expand All @@ -25,7 +23,7 @@ void main() {

await tester.pumpWidget(widget);

final TestUniqueWidgetState state = widget.currentState;
final TestUniqueWidgetState state = widget.currentState!;

expect(state, isNotNull);

Expand Down
20 changes: 9 additions & 11 deletions packages/flutter/test/widgets/value_listenable_builder_test.dart
Expand Up @@ -2,24 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

void main() {
SpyStringValueNotifier valueListenable;
Widget textBuilderUnderTest;
late SpyStringValueNotifier valueListenable;
late Widget textBuilderUnderTest;

Widget builderForValueListenable(
ValueListenable<String> valueListenable,
ValueListenable<String?> valueListenable,
) {
return Directionality(
textDirection: TextDirection.ltr,
child: ValueListenableBuilder<String>(
child: ValueListenableBuilder<String?>(
valueListenable: valueListenable,
builder: (BuildContext context, String value, Widget child) {
builder: (BuildContext context, String? value, Widget? child) {
if (value == null)
return const Placeholder();
return Text(value);
Expand Down Expand Up @@ -67,7 +65,7 @@ void main() {
await tester.pump();
expect(find.text('Gilfoyle'), findsOneWidget);

final ValueListenable<String> differentListenable =
final ValueListenable<String?> differentListenable =
SpyStringValueNotifier('Hendricks');

await tester.pumpWidget(builderForValueListenable(differentListenable));
Expand All @@ -83,7 +81,7 @@ void main() {
await tester.pump();
expect(find.text('Gilfoyle'), findsOneWidget);

final ValueListenable<String> differentListenable =
final ValueListenable<String?> differentListenable =
SpyStringValueNotifier('Hendricks');

await tester.pumpWidget(builderForValueListenable(differentListenable));
Expand Down Expand Up @@ -113,8 +111,8 @@ void main() {
});
}

class SpyStringValueNotifier extends ValueNotifier<String> {
SpyStringValueNotifier(String initialValue) : super(initialValue);
class SpyStringValueNotifier extends ValueNotifier<String?> {
SpyStringValueNotifier(String? initialValue) : super(initialValue);

/// Override for test visibility only.
@override
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter/test/widgets/visibility_test.dart
Expand Up @@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import '../rendering/mock_canvas.dart';
import 'semantics_tester.dart';

class TestState extends StatefulWidget {
const TestState({ Key key, this.child, this.log }) : super(key: key);
const TestState({ Key? key, required this.child, required this.log }) : super(key: key);
final Widget child;
final List<String> log;
@override
Expand Down