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

@@ -12,18 +12,16 @@ void main() {
}
class ScrollEndNotificationApp extends StatelessWidget {
const ScrollEndNotificationApp({ super.key });
const ScrollEndNotificationApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ScrollEndNotificationExample(),
);
return const MaterialApp(home: ScrollEndNotificationExample());
}
}
class ScrollEndNotificationExample extends StatefulWidget {
const ScrollEndNotificationExample({ super.key });
const ScrollEndNotificationExample({super.key});
@override
State<ScrollEndNotificationExample> createState() => _ScrollEndNotificationExampleState();
@@ -60,7 +58,10 @@ class _ScrollEndNotificationExampleState extends State<ScrollEndNotificationExam
}
if (notification is ScrollEndNotification) {
final ScrollMetrics m = notification.metrics;
final int lastIndex = ((m.extentBefore + m.extentInside) ~/ itemExtent).clamp(0, itemCount - 1);
final int lastIndex = ((m.extentBefore + m.extentInside) ~/ itemExtent).clamp(
0,
itemCount - 1,
);
final double alignedScrollOffset = itemExtent * (lastIndex + 1) - m.extentInside;
final double scrollOffset = scrollController.position.pixels;
if (scrollOffset > 0 && (scrollOffset - lastScrollOffset).abs() > itemExtent) {
@@ -92,15 +93,12 @@ class _ScrollEndNotificationExampleState extends State<ScrollEndNotificationExam
slivers: <Widget>[
SliverFixedExtentList(
itemExtent: itemExtent,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Item(
title: 'Item $index',
color: Color.lerp(Colors.red, Colors.blue, index / itemCount)!
);
},
childCount: itemCount,
),
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Item(
title: 'Item $index',
color: Color.lerp(Colors.red, Colors.blue, index / itemCount)!,
);
}, childCount: itemCount),
),
],
),
@@ -113,19 +111,13 @@ class _ScrollEndNotificationExampleState extends State<ScrollEndNotificationExam
}
class Item extends StatelessWidget {
const Item({ super.key, required this.title, required this.color });
const Item({super.key, required this.title, required this.color});
final String title;
final Color color;
@override
Widget build(BuildContext context) {
return Card(
color: color,
child: ListTile(
textColor: Colors.white,
title: Text(title),
),
);
return Card(color: color, child: ListTile(textColor: Colors.white, title: Text(title)));
}
}

View File

@@ -11,7 +11,7 @@ void main() {
}
class SliverAutoScrollExampleApp extends StatelessWidget {
const SliverAutoScrollExampleApp({ super.key });
const SliverAutoScrollExampleApp({super.key});
@override
Widget build(BuildContext context) {
@@ -20,7 +20,7 @@ class SliverAutoScrollExampleApp extends StatelessWidget {
}
class SliverAutoScrollExample extends StatefulWidget {
const SliverAutoScrollExample({ super.key });
const SliverAutoScrollExample({super.key});
@override
State<SliverAutoScrollExample> createState() => _SliverAutoScrollExampleState();
@@ -66,7 +66,8 @@ class _SliverAutoScrollExampleState extends State<SliverAutoScrollExample> {
return;
}
final double overflow = geometry.maxPaintExtent - geometry.paintExtent;
if (overflow > 0 && overflow < geometry.scrollExtent) { // indicates partial visibility
if (overflow > 0 && overflow < geometry.scrollExtent) {
// indicates partial visibility
if (sliverOffset > 0) {
autoScrollTo(constraints.precedingScrollExtent); // top
} else if (sliverOffset == 0) {
@@ -85,7 +86,7 @@ class _SliverAutoScrollExampleState extends State<SliverAutoScrollExample> {
if (notification is ScrollEndNotification) {
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
final RenderSliver? sliver =
alignedItemKey.currentContext?.findAncestorRenderObjectOfType<RenderSliver>();
alignedItemKey.currentContext?.findAncestorRenderObjectOfType<RenderSliver>();
if (sliver != null && sliver.geometry != null) {
maybeAutoScrollAlignedItem(sliver);
}
@@ -110,18 +111,12 @@ class _SliverAutoScrollExampleState extends State<SliverAutoScrollExample> {
child: CustomScrollView(
controller: scrollController,
slivers: <Widget>[
const SliverPadding(
padding: horizontalPadding,
sliver: ItemList(itemCount: 15),
),
const SliverPadding(padding: horizontalPadding, sliver: ItemList(itemCount: 15)),
SliverPadding(
padding: horizontalPadding,
sliver: BigOrangeSliver(sliverChildKey: alignedItemKey),
),
const SliverPadding(
padding: horizontalPadding,
sliver: ItemList(itemCount: 25),
),
const SliverPadding(padding: horizontalPadding, sliver: ItemList(itemCount: 25)),
],
),
),
@@ -136,7 +131,7 @@ class _SliverAutoScrollExampleState extends State<SliverAutoScrollExample> {
// the aligned sliver's child so that we can find the this item's RenderSliver
// later with BuildContext.findAncestorRenderObjectOfType.
class BigOrangeSliver extends StatelessWidget {
const BigOrangeSliver({ super.key, required this.sliverChildKey });
const BigOrangeSliver({super.key, required this.sliverChildKey});
final Key sliverChildKey;
@@ -154,7 +149,7 @@ class BigOrangeSliver extends StatelessWidget {
padding: EdgeInsets.symmetric(vertical: 32),
child: Text('Aligned Item'),
),
)
),
),
),
);
@@ -163,7 +158,7 @@ class BigOrangeSliver extends StatelessWidget {
// A placeholder SliverList of 50 items.
class ItemList extends StatelessWidget {
const ItemList({ super.key, this.itemCount = 50 });
const ItemList({super.key, this.itemCount = 50});
final int itemCount;
@@ -171,18 +166,18 @@ class ItemList extends StatelessWidget {
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Card(
color: colorScheme.onSecondary,
child: SizedBox(width: 100, child: ListTile(
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Card(
color: colorScheme.onSecondary,
child: SizedBox(
width: 100,
child: ListTile(
textColor: colorScheme.secondary,
title: Text('Item $index.$itemCount'),
)),
);
},
childCount: itemCount,
),
),
),
);
}, childCount: itemCount),
);
}
}