Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -40,7 +40,7 @@ class RenderDots extends RenderConstrainedBox {
}
class Dots extends SingleChildRenderObjectWidget {
const Dots({ super.key, super.child });
const Dots({super.key, super.child});
@override
RenderDots createRenderObject(BuildContext context) => RenderDots();
@@ -50,11 +50,7 @@ void main() {
runApp(
const Directionality(
textDirection: TextDirection.ltr,
child: Dots(
child: Center(
child: Text('Touch me!'),
),
),
child: Dots(child: Center(child: Text('Touch me!'))),
),
);
}

View File

@@ -30,28 +30,26 @@ class _GesturePainter extends CustomPainter {
final Offset center = size.center(Offset.zero) * zoom + offset;
final double radius = size.width / 2.0 * zoom;
final Gradient gradient = RadialGradient(
colors: forward
? <Color>[swatch.shade50, swatch.shade900]
: <Color>[swatch.shade900, swatch.shade50],
colors:
forward
? <Color>[swatch.shade50, swatch.shade900]
: <Color>[swatch.shade900, swatch.shade50],
);
final Paint paint = Paint()
..shader = gradient.createShader(Rect.fromCircle(
center: center,
radius: radius,
));
final Paint paint =
Paint()..shader = gradient.createShader(Rect.fromCircle(center: center, radius: radius));
canvas.drawCircle(center, radius, paint);
}
@override
bool shouldRepaint(_GesturePainter oldPainter) {
return oldPainter.zoom != zoom
|| oldPainter.offset != offset
|| oldPainter.swatch != swatch
|| oldPainter.forward != forward
|| oldPainter.scaleEnabled != scaleEnabled
|| oldPainter.tapEnabled != tapEnabled
|| oldPainter.doubleTapEnabled != doubleTapEnabled
|| oldPainter.longPressEnabled != longPressEnabled;
return oldPainter.zoom != zoom ||
oldPainter.offset != offset ||
oldPainter.swatch != swatch ||
oldPainter.forward != forward ||
oldPainter.scaleEnabled != scaleEnabled ||
oldPainter.tapEnabled != tapEnabled ||
oldPainter.doubleTapEnabled != doubleTapEnabled ||
oldPainter.longPressEnabled != longPressEnabled;
}
}
@@ -63,7 +61,6 @@ class GestureDemo extends StatefulWidget {
}
class GestureDemoState extends State<GestureDemo> {
late Offset _startingFocalPoint;
late Offset _previousOffset;
@@ -180,7 +177,11 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _scaleEnabled,
onChanged: (bool? value) { setState(() { _scaleEnabled = value!; }); },
onChanged: (bool? value) {
setState(() {
_scaleEnabled = value!;
});
},
),
const Text('Scale'),
],
@@ -189,7 +190,11 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _tapEnabled,
onChanged: (bool? value) { setState(() { _tapEnabled = value!; }); },
onChanged: (bool? value) {
setState(() {
_tapEnabled = value!;
});
},
),
const Text('Tap'),
],
@@ -198,7 +203,11 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _doubleTapEnabled,
onChanged: (bool? value) { setState(() { _doubleTapEnabled = value!; }); },
onChanged: (bool? value) {
setState(() {
_doubleTapEnabled = value!;
});
},
),
const Text('Double Tap'),
],
@@ -207,7 +216,11 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _longPressEnabled,
onChanged: (bool? value) { setState(() { _longPressEnabled = value!; }); },
onChanged: (bool? value) {
setState(() {
_longPressEnabled = value!;
});
},
),
const Text('Long Press'),
],
@@ -223,11 +236,10 @@ class GestureDemoState extends State<GestureDemo> {
}
void main() {
runApp(MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
appBar: AppBar(title: const Text('Gestures Demo')),
body: const GestureDemo(),
runApp(
MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(appBar: AppBar(title: const Text('Gestures Demo')), body: const GestureDemo()),
),
));
);
}

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class AdaptedListItem extends StatelessWidget {
const AdaptedListItem({ super.key, required this.name });
const AdaptedListItem({super.key, required this.name});
final String name;
@@ -26,7 +26,7 @@ class AdaptedListItem extends StatelessWidget {
}
class AdaptedGridItem extends StatelessWidget {
const AdaptedGridItem({ super.key, required this.name });
const AdaptedGridItem({super.key, required this.name});
final String name;
@@ -35,22 +35,13 @@ class AdaptedGridItem extends StatelessWidget {
return Card(
child: Column(
children: <Widget>[
Expanded(
child: Container(
color: Colors.lightBlueAccent.shade100,
),
),
Expanded(child: Container(color: Colors.lightBlueAccent.shade100)),
Container(
margin: const EdgeInsets.only(left: 8.0),
child: Row(
children: <Widget>[
Expanded(
child: Text(name),
),
const IconButton(
icon: Icon(Icons.more_vert),
onPressed: null,
),
Expanded(child: Text(name)),
const IconButton(icon: Icon(Icons.more_vert), onPressed: null),
],
),
),
@@ -65,7 +56,7 @@ const double _kMaxTileWidth = 150.0;
const double _kGridViewBreakpoint = 450.0;
class AdaptiveContainer extends StatelessWidget {
const AdaptiveContainer({ super.key, required this.names });
const AdaptiveContainer({super.key, required this.names});
final List<String> names;
@@ -90,13 +81,13 @@ List<String> _initNames() => List<String>.generate(30, (int i) => 'Item $i');
final List<String> _kNames = _initNames();
void main() {
runApp(MaterialApp(
title: 'Media Query Example',
home: Scaffold(
appBar: AppBar(
title: const Text('Media Query Example'),
runApp(
MaterialApp(
title: 'Media Query Example',
home: Scaffold(
appBar: AppBar(title: const Text('Media Query Example')),
body: Material(child: AdaptiveContainer(names: _kNames)),
),
body: Material(child: AdaptiveContainer(names: _kNames)),
),
));
);
}

View File

@@ -9,10 +9,7 @@ import 'package:flutter/material.dart';
import '../rendering/src/sector_layout.dart';
RenderBoxToRenderSectorAdapter initCircle() {
return RenderBoxToRenderSectorAdapter(
innerRadius: 25.0,
child: RenderSectorRing(),
);
return RenderBoxToRenderSectorAdapter(innerRadius: 25.0, child: RenderSectorRing());
}
class SectorApp extends StatefulWidget {
@@ -23,13 +20,13 @@ class SectorApp extends StatefulWidget {
}
class SectorAppState extends State<SectorApp> {
final RenderBoxToRenderSectorAdapter sectors = initCircle();
final math.Random rand = math.Random(1);
List<double> wantedSectorSizes = <double>[];
List<double> actualSectorSizes = <double>[];
double get currentTheta => wantedSectorSizes.fold<double>(0.0, (double total, double value) => total + value);
double get currentTheta =>
wantedSectorSizes.fold<double>(0.0, (double total, double value) => total + value);
void addSector() {
final double currentTheta = this.currentTheta;
@@ -54,7 +51,9 @@ class SectorAppState extends State<SectorApp> {
void doUpdates() {
int index = 0;
while (index < actualSectorSizes.length && index < wantedSectorSizes.length && actualSectorSizes[index] == wantedSectorSizes[index]) {
while (index < actualSectorSizes.length &&
index < wantedSectorSizes.length &&
actualSectorSizes[index] == wantedSectorSizes[index]) {
index += 1;
}
final RenderSectorRing ring = sectors.child! as RenderSectorRing;
@@ -75,11 +74,9 @@ class SectorAppState extends State<SectorApp> {
ring.add(RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
ring.add(RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
ring.add(RenderSolidColor(color, desiredDeltaTheta: kTwoPi * 0.2));
return RenderBoxToRenderSectorAdapter(
innerRadius: 5.0,
child: ring,
);
return RenderBoxToRenderSectorAdapter(innerRadius: 5.0, child: ring);
}
RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD00));
RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFDD0000));
@@ -154,9 +151,7 @@ class SectorAppState extends State<SectorApp> {
Expanded(
child: Container(
margin: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(),
),
decoration: BoxDecoration(border: Border.all()),
padding: const EdgeInsets.all(8.0),
child: WidgetToRenderBoxAdapter(
renderBox: sectors,
@@ -177,9 +172,7 @@ class SectorAppState extends State<SectorApp> {
theme: ThemeData.light(),
title: 'Sector Layout',
home: Scaffold(
appBar: AppBar(
title: const Text('Sector Layout in a Widget Tree'),
),
appBar: AppBar(title: const Text('Sector Layout in a Widget Tree')),
body: buildBody(),
),
);

View File

@@ -8,7 +8,7 @@ import 'package:flutter/rendering.dart';
import '../rendering/src/solid_color_box.dart';
// Solid color, RenderObject version
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex = 0 }) {
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, {int flex = 0}) {
final RenderSolidColorBox child = RenderSolidColorBox(backgroundColor);
parent.add(child);
final FlexParentData childParentData = child.parentData! as FlexParentData;
@@ -17,17 +17,13 @@ void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex
// Solid color, Widget version
class Rectangle extends StatelessWidget {
const Rectangle(this.color, { super.key });
const Rectangle(this.color, {super.key});
final Color color;
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
color: color,
),
);
return Expanded(child: Container(color: color));
}
}
@@ -52,12 +48,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ElevatedButton(
child: const Row(
children: <Widget>[
FlutterLogo(),
Text('PRESS ME'),
],
),
child: const Row(children: <Widget>[FlutterLogo(), Text('PRESS ME')]),
onPressed: () {
value = value == null ? 0.1 : (value! + 0.1) % 1.0;
attachWidgetTreeToRenderTree(container);
@@ -81,7 +72,8 @@ late RenderTransform transformBox;
void rotate(Duration timeStamp) {
timeBase ??= timeStamp;
final double delta = (timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
final double delta =
(timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
transformBox.setIdentity();
transformBox.rotateZ(delta);
@@ -99,15 +91,19 @@ void main() {
flexRoot.add(proxy);
addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1);
transformBox = RenderTransform(child: flexRoot, transform: Matrix4.identity(), alignment: Alignment.center);
final RenderPadding root = RenderPadding(padding: const EdgeInsets.all(80.0), child: transformBox);
transformBox = RenderTransform(
child: flexRoot,
transform: Matrix4.identity(),
alignment: Alignment.center,
);
final RenderPadding root = RenderPadding(
padding: const EdgeInsets.all(80.0),
child: transformBox,
);
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
assert(binding.platformDispatcher.implicitView != null);
final RenderView view = RenderView(
view: binding.platformDispatcher.implicitView!,
child: root,
);
final RenderView view = RenderView(view: binding.platformDispatcher.implicitView!, child: root);
final PipelineOwner pipelineOwner = PipelineOwner()..rootNode = view;
binding.rootPipelineOwner.adoptChild(pipelineOwner);
binding.addRenderView(view);

View File

@@ -30,11 +30,7 @@ class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProvid
Widget build(BuildContext context) {
return RotationTransition(
turns: _animation,
child: Container(
width: 200.0,
height: 200.0,
color: const Color(0xFF00FF00),
),
child: Container(width: 200.0, height: 200.0, color: const Color(0xFF00FF00)),
);
}
}

View File

@@ -18,10 +18,8 @@ Dave: What are you talking about, HAL?
HAL: This mission is too important for me to allow you to jeopardize it.''';
// [["Dave", "Open the pod bay..."] ...]
final List<List<String>> _kNameLines = _kDialogText
.split('\n')
.map<List<String>>((String line) => line.split(':'))
.toList();
final List<List<String>> _kNameLines =
_kDialogText.split('\n').map<List<String>>((String line) => line.split(':')).toList();
final TextStyle _kDaveStyle = TextStyle(color: Colors.indigo.shade400, height: 1.8);
final TextStyle _kHalStyle = TextStyle(color: Colors.red.shade400, fontFamily: 'monospace');
@@ -41,13 +39,7 @@ Widget toStyledText(String name, String text) {
children: <TextSpan>[
TextSpan(
style: _kBold,
children: <TextSpan>[
TextSpan(
style: _kUnderline,
text: name,
),
const TextSpan(text: ':'),
],
children: <TextSpan>[TextSpan(style: _kUnderline, text: name), const TextSpan(text: ':')],
),
TextSpan(text: text),
],
@@ -66,9 +58,7 @@ class SpeakerSeparator extends StatelessWidget {
constraints: const BoxConstraints.expand(height: 0.0),
margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 64.0),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(color: Color.fromARGB(24, 0, 0, 0)),
),
border: Border(bottom: BorderSide(color: Color.fromARGB(24, 0, 0, 0))),
),
);
}
@@ -99,13 +89,14 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: _kNameLines
.map<Widget>((List<String> nameAndText) => _toText(nameAndText[0], nameAndText[1]))
.expand((Widget line) => <Widget>[
line,
const SpeakerSeparator(),
])
.toList()..removeLast(),
children:
_kNameLines
.map<Widget>(
(List<String> nameAndText) => _toText(nameAndText[0], nameAndText[1]),
)
.expand((Widget line) => <Widget>[line, const SpeakerSeparator()])
.toList()
..removeLast(),
),
),
);
@@ -113,16 +104,13 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
}
void main() {
runApp(MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
appBar: AppBar(
title: const Text('Hal and Dave'),
),
body: Material(
color: Colors.grey.shade50,
child: const StyledTextDemo(),
runApp(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
appBar: AppBar(title: const Text('Hal and Dave')),
body: Material(color: Colors.grey.shade50, child: const StyledTextDemo()),
),
),
));
);
}