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

@@ -13,9 +13,7 @@ class CustomScrollViewExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: CustomScrollViewExample(),
);
return const MaterialApp(home: CustomScrollViewExample());
}
}
@@ -50,31 +48,25 @@ class _CustomScrollViewExampleState extends State<CustomScrollViewExample> {
center: centerKey,
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + top[index] % 4 * 100],
height: 100 + top[index] % 4 * 20.0,
child: Text('Item: ${top[index]}'),
);
},
childCount: top.length,
),
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + top[index] % 4 * 100],
height: 100 + top[index] % 4 * 20.0,
child: Text('Item: ${top[index]}'),
);
}, childCount: top.length),
),
SliverList(
key: centerKey,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + bottom[index] % 4 * 100],
height: 100 + bottom[index] % 4 * 20.0,
child: Text('Item: ${bottom[index]}'),
);
},
childCount: bottom.length,
),
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
alignment: Alignment.center,
color: Colors.blue[200 + bottom[index] % 4 * 100],
height: 100 + bottom[index] % 4 * 20.0,
child: Text('Item: ${bottom[index]}'),
);
}, childCount: bottom.length),
),
],
),

View File

@@ -35,11 +35,9 @@ class GridViewExampleApp extends StatelessWidget {
child: Container(
margin: const EdgeInsets.all(12.0),
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
gradient: const RadialGradient(
colors: <Color>[ Color(0x0F88EEFF), Color(0x2F0099BB) ],
colors: <Color>[Color(0x0F88EEFF), Color(0x2F0099BB)],
),
),
child: FlutterLogo(
@@ -56,7 +54,7 @@ class GridViewExampleApp extends StatelessWidget {
}
class CustomGridDelegate extends SliverGridDelegate {
CustomGridDelegate({ required this.dimension });
CustomGridDelegate({required this.dimension});
// This is the desired height of each row (and width of each square).
// When there is not enough room, we shrink this to the width of the scroll view.
@@ -112,8 +110,8 @@ class CustomGridLayout extends SliverGridLayout {
if (childCount == 0 || dimension == 0) {
return 0;
}
return (childCount ~/ loopLength) * loopHeight
+ ((childCount % loopLength) ~/ crossAxisCount) * dimension;
return (childCount ~/ loopLength) * loopHeight +
((childCount % loopLength) ~/ crossAxisCount) * dimension;
}
@override

View File

@@ -13,9 +13,7 @@ class ListViewExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ListTileSelectExample(),
);
return const MaterialApp(home: ListTileSelectExample());
}
}
@@ -52,12 +50,11 @@ class ListTileSelectExampleState extends State<ListTileSelectExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'ListTile selection',
),
leading: isSelectionMode
? IconButton(
appBar: AppBar(
title: const Text('ListTile selection'),
leading:
isSelectionMode
? IconButton(
icon: const Icon(Icons.close),
onPressed: () {
setState(() {
@@ -66,64 +63,62 @@ class ListTileSelectExampleState extends State<ListTileSelectExample> {
initializeSelection();
},
)
: const SizedBox(),
actions: <Widget>[
if (_isGridMode)
IconButton(
icon: const Icon(Icons.grid_on),
onPressed: () {
: const SizedBox(),
actions: <Widget>[
if (_isGridMode)
IconButton(
icon: const Icon(Icons.grid_on),
onPressed: () {
setState(() {
_isGridMode = false;
});
},
)
else
IconButton(
icon: const Icon(Icons.list),
onPressed: () {
setState(() {
_isGridMode = true;
});
},
),
if (isSelectionMode)
TextButton(
child:
!_selectAll
? const Text('select all', style: TextStyle(color: Colors.white))
: const Text('unselect all', style: TextStyle(color: Colors.white)),
onPressed: () {
_selectAll = !_selectAll;
setState(() {
_selected = List<bool>.generate(listLength, (_) => _selectAll);
});
},
),
],
),
body:
_isGridMode
? GridBuilder(
isSelectionMode: isSelectionMode,
selectedList: _selected,
onSelectionChange: (bool x) {
setState(() {
_isGridMode = false;
isSelectionMode = x;
});
},
)
else
IconButton(
icon: const Icon(Icons.list),
onPressed: () {
: ListBuilder(
isSelectionMode: isSelectionMode,
selectedList: _selected,
onSelectionChange: (bool x) {
setState(() {
_isGridMode = true;
isSelectionMode = x;
});
},
),
if (isSelectionMode)
TextButton(
child: !_selectAll
? const Text(
'select all',
style: TextStyle(color: Colors.white),
)
: const Text(
'unselect all',
style: TextStyle(color: Colors.white),
),
onPressed: () {
_selectAll = !_selectAll;
setState(() {
_selected = List<bool>.generate(listLength, (_) => _selectAll);
});
}),
],
),
body: _isGridMode
? GridBuilder(
isSelectionMode: isSelectionMode,
selectedList: _selected,
onSelectionChange: (bool x) {
setState(() {
isSelectionMode = x;
});
},
)
: ListBuilder(
isSelectionMode: isSelectionMode,
selectedList: _selected,
onSelectionChange: (bool x) {
setState(() {
isSelectionMode = x;
});
},
));
);
}
}
@@ -155,27 +150,33 @@ class GridBuilderState extends State<GridBuilder> {
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: widget.selectedList.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemBuilder: (_, int index) {
return InkWell(
onTap: () => _toggle(index),
onLongPress: () {
if (!widget.isSelectionMode) {
setState(() {
widget.selectedList[index] = true;
});
widget.onSelectionChange!(true);
}
},
child: GridTile(
child: Container(
child: widget.isSelectionMode
? Checkbox(onChanged: (bool? x) => _toggle(index), value: widget.selectedList[index])
: const Icon(Icons.image),
)),
);
});
itemCount: widget.selectedList.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemBuilder: (_, int index) {
return InkWell(
onTap: () => _toggle(index),
onLongPress: () {
if (!widget.isSelectionMode) {
setState(() {
widget.selectedList[index] = true;
});
widget.onSelectionChange!(true);
}
},
child: GridTile(
child: Container(
child:
widget.isSelectionMode
? Checkbox(
onChanged: (bool? x) => _toggle(index),
value: widget.selectedList[index],
)
: const Icon(Icons.image),
),
),
);
},
);
}
}
@@ -207,25 +208,28 @@ class _ListBuilderState extends State<ListBuilder> {
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: widget.selectedList.length,
itemBuilder: (_, int index) {
return ListTile(
onTap: () => _toggle(index),
onLongPress: () {
if (!widget.isSelectionMode) {
setState(() {
widget.selectedList[index] = true;
});
widget.onSelectionChange!(true);
}
},
trailing: widget.isSelectionMode
itemCount: widget.selectedList.length,
itemBuilder: (_, int index) {
return ListTile(
onTap: () => _toggle(index),
onLongPress: () {
if (!widget.isSelectionMode) {
setState(() {
widget.selectedList[index] = true;
});
widget.onSelectionChange!(true);
}
},
trailing:
widget.isSelectionMode
? Checkbox(
value: widget.selectedList[index],
onChanged: (bool? x) => _toggle(index),
)
value: widget.selectedList[index],
onChanged: (bool? x) => _toggle(index),
)
: const SizedBox.shrink(),
title: Text('item $index'));
});
title: Text('item $index'),
);
},
);
}
}

View File

@@ -39,10 +39,7 @@ class _ListViewExampleState extends State<ListViewExample> {
child: ListView.custom(
childrenDelegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return KeepAliveItem(
data: items[index],
key: ValueKey<String>(items[index]),
);
return KeepAliveItem(data: items[index], key: ValueKey<String>(items[index]));
},
childCount: items.length,
findChildIndexCallback: (Key key) {
@@ -61,10 +58,7 @@ class _ListViewExampleState extends State<ListViewExample> {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: () => _reverse(),
child: const Text('Reverse items'),
),
TextButton(onPressed: () => _reverse(), child: const Text('Reverse items')),
],
),
),
@@ -73,10 +67,7 @@ class _ListViewExampleState extends State<ListViewExample> {
}
class KeepAliveItem extends StatefulWidget {
const KeepAliveItem({
required Key super.key,
required this.data,
});
const KeepAliveItem({required Key super.key, required this.data});
final String data;
@@ -84,8 +75,7 @@ class KeepAliveItem extends StatefulWidget {
State<KeepAliveItem> createState() => _KeepAliveItemState();
}
class _KeepAliveItemState extends State<KeepAliveItem>
with AutomaticKeepAliveClientMixin {
class _KeepAliveItemState extends State<KeepAliveItem> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;