Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/manual_tests/lib/star_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _MyHomePageState extends State<MyHomePage> {
color: Colors.blue.shade100,
shape: lerpBorder(
StarBorder.polygon(
side: const BorderSide(strokeAlign: StrokeAlign.center, width: 2),
side: const BorderSide(strokeAlign: BorderSide.strokeAlignCenter, width: 2),
sides: _model.points,
pointRounding: _model.pointRounding,
rotation: _model.rotation,
Expand All @@ -102,7 +102,7 @@ class _MyHomePageState extends State<MyHomePage> {
color: Colors.blue.shade100,
shape: lerpBorder(
StarBorder(
side: const BorderSide(strokeAlign: StrokeAlign.center, width: 2),
side: const BorderSide(strokeAlign: BorderSide.strokeAlignCenter, width: 2),
points: _model.points,
innerRadiusRatio: _model.innerRadiusRatio,
pointRounding: _model.pointRounding,
Expand Down
204 changes: 204 additions & 0 deletions examples/api/lib/painting/borders/border_side.0.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// 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.

/// Flutter code sample for [BorderSide].

import 'package:flutter/material.dart';

void main() => runApp(const BorderSideApp());

class BorderSideApp extends StatelessWidget {
const BorderSideApp({super.key});

@override
Widget build(BuildContext context) {
return const MaterialApp(home: BorderSideExample());
}
}

class BorderSideExample extends StatefulWidget {
const BorderSideExample({super.key});

@override
State<BorderSideExample> createState() => _BorderSideExampleState();
}

class _BorderSideExampleState extends State<BorderSideExample>
with TickerProviderStateMixin {
late final AnimationController animation;

@override
void initState() {
super.initState();
animation =
AnimationController(vsync: this, duration: const Duration(seconds: 1));
animation.repeat(reverse: true);
animation.addListener(_markDirty);
}

@override
void dispose() {
animation.dispose();
super.dispose();
}

void _markDirty() {
setState(() {});
}

static const double borderWidth = 10;
static const double cornerRadius = 10;
static const Color borderColor = Color(0x8000b4fc);

@override
Widget build(BuildContext context) {
return Material(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TestBox(
shape: StadiumBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TestBox(
shape: CircleBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
TestBox(
shape: OvalBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TestBox(
shape: BeveledRectangleBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
TestBox(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(cornerRadius),
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TestBox(
shape: RoundedRectangleBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
TestBox(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(cornerRadius),
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TestBox(
shape: StarBorder(
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
TestBox(
shape: StarBorder(
pointRounding: 1,
innerRadiusRatio: 0.5,
points: 8,
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
TestBox(
shape: StarBorder.polygon(
sides: 6,
pointRounding: 0.5,
side: BorderSide(
color: borderColor,
width: borderWidth,
strokeAlign: (animation.value * 2) - 1,
),
),
),
],
),
],
),
),
);
}
}

class TestBox extends StatelessWidget {
const TestBox({
super.key,
required this.shape,
});

final ShapeBorder shape;

@override
Widget build(BuildContext context) {
return Container(
width: 100,
height: 50,
decoration: ShapeDecoration(
color: const Color(0xff012677),
shape: shape,
),
);
}
}
21 changes: 21 additions & 0 deletions examples/api/test/painting/border_side.0_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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_api_samples/painting/borders/border_side.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('Finds the expected TestBox', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.BorderSideExample(),
),
);

expect(find.byType(example.BorderSideExample), findsOneWidget);
expect(find.byType(example.TestBox), findsNWidgets(10));
});
}
45 changes: 2 additions & 43 deletions packages/flutter/lib/src/painting/beveled_rectangle_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:flutter/foundation.dart';
import 'basic_types.dart';
import 'border_radius.dart';
import 'borders.dart';
import 'edge_insets.dart';

/// A rectangular border with flattened or "beveled" corners.
///
Expand Down Expand Up @@ -40,18 +39,6 @@ class BeveledRectangleBorder extends OutlinedBorder {
/// [getOuterPath].
final BorderRadiusGeometry borderRadius;

@override
EdgeInsetsGeometry get dimensions {
switch (side.strokeAlign) {
case StrokeAlign.inside:
return EdgeInsets.all(side.width);
case StrokeAlign.center:
return EdgeInsets.all(side.width / 2);
case StrokeAlign.outside:
return EdgeInsets.zero;
}
}

@override
ShapeBorder scale(double t) {
return BeveledRectangleBorder(
Expand Down Expand Up @@ -125,21 +112,7 @@ class BeveledRectangleBorder extends OutlinedBorder {

@override
Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect);
final RRect adjustedRect;
switch (side.strokeAlign) {
case StrokeAlign.inside:
adjustedRect = borderRect.deflate(side.width);
break;
case StrokeAlign.center:
adjustedRect = borderRect.deflate(side.width / 2);
break;
case StrokeAlign.outside:
adjustedRect = borderRect;
break;
}

return _getPath(adjustedRect);
return _getPath(borderRadius.resolve(textDirection).toRRect(rect).deflate(side.strokeInset));
}

@override
Expand All @@ -156,21 +129,7 @@ class BeveledRectangleBorder extends OutlinedBorder {
case BorderStyle.none:
break;
case BorderStyle.solid:
final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect);
final RRect adjustedRect;
switch (side.strokeAlign) {
case StrokeAlign.inside:
adjustedRect = borderRect;
break;
case StrokeAlign.center:
adjustedRect = borderRect.inflate(side.width / 2);
break;
case StrokeAlign.outside:
adjustedRect = borderRect.inflate(side.width);
break;
}
final Path path = _getPath(adjustedRect)
..addPath(getInnerPath(rect, textDirection: textDirection), Offset.zero);
final Path path = _getPath(borderRadius.resolve(textDirection).toRRect(rect).inflate(side.strokeOffset / 2));
canvas.drawPath(path, side.toPaint());
break;
}
Expand Down
Loading