Fix OutlineInputBorder crash (#30123)
This commit is contained in:
@@ -412,7 +412,7 @@ class OutlineInputBorder extends InputBorder {
|
|||||||
|
|
||||||
const double cornerArcSweep = math.pi / 2.0;
|
const double cornerArcSweep = math.pi / 2.0;
|
||||||
final double tlCornerArcSweep = start < center.tlRadiusX
|
final double tlCornerArcSweep = start < center.tlRadiusX
|
||||||
? math.asin(start / center.tlRadiusX)
|
? math.asin((start / center.tlRadiusX).clamp(-1.0, 1.0))
|
||||||
: math.pi / 2.0;
|
: math.pi / 2.0;
|
||||||
|
|
||||||
final Path path = Path()
|
final Path path = Path()
|
||||||
@@ -474,12 +474,12 @@ class OutlineInputBorder extends InputBorder {
|
|||||||
final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
|
final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
|
||||||
switch (textDirection) {
|
switch (textDirection) {
|
||||||
case TextDirection.rtl: {
|
case TextDirection.rtl: {
|
||||||
final Path path = _gapBorderPath(canvas, center, gapStart + gapPadding - extent, extent);
|
final Path path = _gapBorderPath(canvas, center, math.max(0.0, gapStart + gapPadding - extent), extent);
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextDirection.ltr: {
|
case TextDirection.ltr: {
|
||||||
final Path path = _gapBorderPath(canvas, center, gapStart - gapPadding, extent);
|
final Path path = _gapBorderPath(canvas, center, math.max(0.0, gapStart - gapPadding), extent);
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io' show Platform;
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -2255,6 +2256,41 @@ void main() {
|
|||||||
expect(getBorderRadius(tester), BorderRadius.zero);
|
expect(getBorderRadius(tester), BorderRadius.zero);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('OutlineInputBorder async lerp', (WidgetTester tester) async {
|
||||||
|
// Regression test for https://github.com/flutter/flutter/issues/28724
|
||||||
|
|
||||||
|
final Completer<void> completer = Completer<void>();
|
||||||
|
bool waitIsOver = false;
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: StatefulBuilder(
|
||||||
|
builder: (BuildContext context, StateSetter setState) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
setState(() { waitIsOver = true; });
|
||||||
|
await completer.future;
|
||||||
|
setState(() { waitIsOver = false; });
|
||||||
|
},
|
||||||
|
child: InputDecorator(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Test',
|
||||||
|
enabledBorder: !waitIsOver ? null : const OutlineInputBorder(borderSide: BorderSide(color: Colors.blue)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.byType(StatefulBuilder));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
completer.complete();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
});
|
||||||
|
|
||||||
test('InputBorder equality', () {
|
test('InputBorder equality', () {
|
||||||
// OutlineInputBorder's equality is defined by the borderRadius, borderSide, & gapPadding
|
// OutlineInputBorder's equality is defined by the borderRadius, borderSide, & gapPadding
|
||||||
const OutlineInputBorder outlineInputBorder = OutlineInputBorder(
|
const OutlineInputBorder outlineInputBorder = OutlineInputBorder(
|
||||||
|
|||||||
Reference in New Issue
Block a user