More beautiful linear_gradient sample (#99298)
This commit is contained in:
committed by
GitHub
parent
96426230af
commit
00f3f2b14f
@@ -11,33 +11,41 @@ void main() => runApp(const MyApp());
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
);
|
||||
return const MaterialApp(home: MoodyGradient());
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class MoodyGradient extends StatelessWidget {
|
||||
const MoodyGradient({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end:
|
||||
Alignment(0.8, 0.0), // 10% of the width, so there are ten blinds.
|
||||
colors: <Color>[
|
||||
Color(0xffee0000),
|
||||
Color(0xffeeee00)
|
||||
], // red to yellow
|
||||
tileMode: TileMode.repeated, // repeats the gradient over the canvas
|
||||
return Material(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment(0.8, 1),
|
||||
colors: <Color>[
|
||||
Color(0xff1f005c),
|
||||
Color(0xff5b0060),
|
||||
Color(0xff870160),
|
||||
Color(0xffac255e),
|
||||
Color(0xffca485c),
|
||||
Color(0xffe16b5c),
|
||||
Color(0xfff39060),
|
||||
Color(0xffffb56b),
|
||||
], // Gradient from https://learnui.design/tools/gradient-generator.html
|
||||
tileMode: TileMode.mirror,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'From Night to Day',
|
||||
style: TextStyle(fontSize: 24, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -25,6 +25,8 @@ dev_dependencies:
|
||||
sdk: flutter
|
||||
flutter_driver:
|
||||
sdk: flutter
|
||||
flutter_goldens:
|
||||
sdk: flutter
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
test: 1.20.1
|
||||
|
||||
14
examples/api/test/flutter_test_config.dart
Normal file
14
examples/api/test/flutter_test_config.dart
Normal 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');
|
||||
}
|
||||
5
examples/api/test/goldens_io.dart
Normal file
5
examples/api/test/goldens_io.dart
Normal 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;
|
||||
8
examples/api/test/goldens_web.dart
Normal file
8
examples/api/test/goldens_web.dart
Normal 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();
|
||||
39
examples/api/test/painting/linear_gradient.0_test.dart
Normal file
39
examples/api/test/painting/linear_gradient.0_test.dart
Normal 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'),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user