More beautiful linear_gradient sample (#99298)

This commit is contained in:
Michael Goderbauer
2022-03-02 16:41:21 -08:00
committed by GitHub
parent 96426230af
commit 00f3f2b14f
9 changed files with 155 additions and 32 deletions

View File

@@ -0,0 +1,14 @@
// 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 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'goldens_io.dart' if (dart.library.html) 'goldens_web.dart' as flutter_goldens;
Future<void> testExecutable(FutureOr<void> Function() testMain) {
// Enable golden file testing using Skia Gold.
return flutter_goldens.testExecutable(testMain, namePrefix: 'api');
}

View File

@@ -0,0 +1,5 @@
// 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.
export 'package:flutter_goldens/flutter_goldens.dart' show testExecutable;

View File

@@ -0,0 +1,8 @@
// 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 'dart:async';
// package:flutter_goldens is not used as part of the test process for web.
Future<void> testExecutable(FutureOr<void> Function() testMain) async => testMain();

View File

@@ -0,0 +1,39 @@
// 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/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_api_samples/painting/gradient/linear_gradient.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('finds a gradient', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.MoodyGradient(),
),
);
expect(find.byType(example.MoodyGradient), findsOneWidget);
});
testWidgets('gradient matches golden', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: SizedBox(
width: 800,
height: 600,
child: RepaintBoundary(
child: example.MoodyGradient(),
),
),
),
);
await expectLater(
find.byType(example.MoodyGradient),
matchesGoldenFile('linear_gradient.0_test.png'),
);
});
}