flutter_flutter/packages/flutter/test/painting/shape_border_test.dart
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

175 lines
10 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/painting.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Border.lerp identical a,b', () {
expect(Border.lerp(null, null, 0), null);
const border = Border();
expect(identical(Border.lerp(border, border, 0.5), border), true);
});
test('BoxBorder.lerp identical a,b', () {
expect(BoxBorder.lerp(null, null, 0), null);
const BoxBorder border = Border();
expect(identical(BoxBorder.lerp(border, border, 0.5), border), true);
});
test('BorderDirectional.lep identical a,b', () {
expect(BorderDirectional.lerp(null, null, 0), null);
const border = BorderDirectional();
expect(identical(ShapeBorder.lerp(border, border, 0.5), border), true);
});
test('OutlinedBorder.lep identical a,b', () {
expect(OutlinedBorder.lerp(null, null, 0), null);
const OutlinedBorder border = RoundedRectangleBorder();
expect(identical(OutlinedBorder.lerp(border, border, 0.5), border), true);
});
test('ShapeBorder.lep identical a,b', () {
expect(ShapeBorder.lerp(null, null, 0), null);
const ShapeBorder border = CircleBorder();
expect(identical(ShapeBorder.lerp(border, border, 0.5), border), true);
});
test('Compound borders', () {
final b1 = Border.all(color: const Color(0xFF00FF00));
final b2 = Border.all(color: const Color(0xFF0000FF));
expect(
(b1 + b2).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)})) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}))',
);
expect(
(b1 + (b2 + b2)).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)})) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0))',
);
expect(
((b1 + b2) + b2).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)})) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0))',
);
expect((b1 + b2) + b2, b1 + (b2 + b2));
expect(
(b1 + b2).scale(3.0).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)}, width: 3.0)) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}, width: 3.0))',
);
expect(
(b1 + b2).scale(0.0).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)}, width: 0.0, style: none)) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}, width: 0.0, style: none))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 0.0).toString(),
'Border.all(BorderSide(color: ${const Color(0xff0000ff)})) + '
'Border.all(BorderSide(color: ${const Color(0xff00ff00)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 0.20).toString(),
'Border.all(BorderSide(color: ${const Color(0xff0033cc)})) + '
'Border.all(BorderSide(color: ${const Color(0xff00cc33)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 1 / 3).toString(),
'Border.all(BorderSide(color: ${const Color(0xff0055aa)})) + '
'Border.all(BorderSide(color: ${const Color(0xff00aa55)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 1.0).toString(),
'Border.all(BorderSide(color: ${const Color(0xff00ff00)})) + '
'Border.all(BorderSide(color: ${const Color(0xff0000ff)}))',
);
expect((b1 + b2).dimensions, const EdgeInsets.all(2.0));
const rect = Rect.fromLTRB(11.0, 15.0, 299.0, 175.0);
expect(
(Canvas canvas) => (b1 + b2).paint(canvas, rect),
paints
..rect(rect: rect.deflate(0.5), color: b2.top.color)
..rect(rect: rect.deflate(1.5), color: b1.top.color),
);
expect((b1 + b2 + b1).dimensions, const EdgeInsets.all(3.0));
expect(
(Canvas canvas) => (b1 + b2 + b1).paint(canvas, rect),
paints
..rect(rect: rect.deflate(0.5), color: b1.top.color)
..rect(rect: rect.deflate(1.5), color: b2.top.color)
..rect(rect: rect.deflate(2.5), color: b1.top.color),
);
});
test('Compound borders', () {
const side1 = BorderSide(color: Color(0xFF00FF00));
const side2 = BorderSide(color: Color(0xFF0000FF));
const b1 = BorderDirectional(top: side1, start: side1, end: side1, bottom: side1);
const b2 = BorderDirectional(top: side2, start: side2, end: side2, bottom: side2);
expect(
(b1 + b2).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}), start: BorderSide(color: ${const Color(0xff00ff00)}), end: BorderSide(color: ${const Color(0xff00ff00)}), bottom: BorderSide(color: ${const Color(0xff00ff00)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}), start: BorderSide(color: ${const Color(0xff0000ff)}), end: BorderSide(color: ${const Color(0xff0000ff)}), bottom: BorderSide(color: ${const Color(0xff0000ff)}))',
);
expect(
(b1 + (b2 + b2)).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}), start: BorderSide(color: ${const Color(0xff00ff00)}), end: BorderSide(color: ${const Color(0xff00ff00)}), bottom: BorderSide(color: ${const Color(0xff00ff00)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), start: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), end: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), bottom: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0))',
);
expect(
((b1 + b2) + b2).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}), start: BorderSide(color: ${const Color(0xff00ff00)}), end: BorderSide(color: ${const Color(0xff00ff00)}), bottom: BorderSide(color: ${const Color(0xff00ff00)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), start: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), end: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0), bottom: BorderSide(color: ${const Color(0xff0000ff)}, width: 2.0))',
);
expect((b1 + b2) + b2, b1 + (b2 + b2));
expect(
(b1 + b2).scale(3.0).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}, width: 3.0), start: BorderSide(color: ${const Color(0xff00ff00)}, width: 3.0), end: BorderSide(color: ${const Color(0xff00ff00)}, width: 3.0), bottom: BorderSide(color: ${const Color(0xff00ff00)}, width: 3.0)) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}, width: 3.0), start: BorderSide(color: ${const Color(0xff0000ff)}, width: 3.0), end: BorderSide(color: ${const Color(0xff0000ff)}, width: 3.0), bottom: BorderSide(color: ${const Color(0xff0000ff)}, width: 3.0))',
);
expect(
(b1 + b2).scale(0.0).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}, width: 0.0, style: none), start: BorderSide(color: ${const Color(0xff00ff00)}, width: 0.0, style: none), end: BorderSide(color: ${const Color(0xff00ff00)}, width: 0.0, style: none), bottom: BorderSide(color: ${const Color(0xff00ff00)}, width: 0.0, style: none)) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}, width: 0.0, style: none), start: BorderSide(color: ${const Color(0xff0000ff)}, width: 0.0, style: none), end: BorderSide(color: ${const Color(0xff0000ff)}, width: 0.0, style: none), bottom: BorderSide(color: ${const Color(0xff0000ff)}, width: 0.0, style: none))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 0.0).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}), start: BorderSide(color: ${const Color(0xff0000ff)}), end: BorderSide(color: ${const Color(0xff0000ff)}), bottom: BorderSide(color: ${const Color(0xff0000ff)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}), start: BorderSide(color: ${const Color(0xff00ff00)}), end: BorderSide(color: ${const Color(0xff00ff00)}), bottom: BorderSide(color: ${const Color(0xff00ff00)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 0.20).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0033cc)}), start: BorderSide(color: ${const Color(0xff0033cc)}), end: BorderSide(color: ${const Color(0xff0033cc)}), bottom: BorderSide(color: ${const Color(0xff0033cc)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00cc33)}), start: BorderSide(color: ${const Color(0xff00cc33)}), end: BorderSide(color: ${const Color(0xff00cc33)}), bottom: BorderSide(color: ${const Color(0xff00cc33)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 1 / 3).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0055aa)}), start: BorderSide(color: ${const Color(0xff0055aa)}), end: BorderSide(color: ${const Color(0xff0055aa)}), bottom: BorderSide(color: ${const Color(0xff0055aa)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00aa55)}), start: BorderSide(color: ${const Color(0xff00aa55)}), end: BorderSide(color: ${const Color(0xff00aa55)}), bottom: BorderSide(color: ${const Color(0xff00aa55)}))',
);
expect(
ShapeBorder.lerp(b2 + b1, b1 + b2, 1.0).toString(),
'BorderDirectional(top: BorderSide(color: ${const Color(0xff00ff00)}), start: BorderSide(color: ${const Color(0xff00ff00)}), end: BorderSide(color: ${const Color(0xff00ff00)}), bottom: BorderSide(color: ${const Color(0xff00ff00)})) + '
'BorderDirectional(top: BorderSide(color: ${const Color(0xff0000ff)}), start: BorderSide(color: ${const Color(0xff0000ff)}), end: BorderSide(color: ${const Color(0xff0000ff)}), bottom: BorderSide(color: ${const Color(0xff0000ff)}))',
);
expect((b1 + b2).dimensions, const EdgeInsetsDirectional.fromSTEB(2.0, 2.0, 2.0, 2.0));
const rect = Rect.fromLTRB(11.0, 15.0, 299.0, 175.0);
expect(
(Canvas canvas) => (b1 + b2).paint(canvas, rect, textDirection: TextDirection.rtl),
paints
..rect(rect: rect.deflate(0.5), color: b2.top.color)
..rect(rect: rect.deflate(1.5), color: b1.top.color),
);
expect((b1 + b2 + b1).dimensions, const EdgeInsetsDirectional.fromSTEB(3.0, 3.0, 3.0, 3.0));
expect(
(Canvas canvas) => (b1 + b2 + b1).paint(canvas, rect, textDirection: TextDirection.rtl),
paints
..rect(rect: rect.deflate(0.5), color: b1.top.color)
..rect(rect: rect.deflate(1.5), color: b2.top.color)
..rect(rect: rect.deflate(2.5), color: b1.top.color),
);
});
}