Skip to content

Commit 21cca5b

Browse files
committed
fmt [nfc]: Adjust newline placement to Flutter style
From the Flutter repo I've picked up a preference to avoid a line break just after `=` or `=>`, and in a few similar "cliffhanger" locations. This is paired with a willingness to make some lines longer than 80 columns when that helps readability: https://github.com./flutter/flutter/wiki/Style-guide-for-Flutter-repo#prefer-a-maximum-line-length-of-80-characters https://github.com./flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using-for-short-functions-and-methods We have some such "cliffhanger" newlines in our existing code, much of it in places where the Dart autoformatter put it there before I'd gotten a grasp on what I want to keep from the autoformatter's output and what I don't. So here's a quick sweep through our code fixing those. Conversely, fix a couple of too-long lines, and mismatched formatting of parallel constructs, that I noticed while doing the sweep.
1 parent 36c25ec commit 21cca5b

11 files changed

+71
-59
lines changed

lib/api/model/events.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ class MessageEvent extends Event {
202202
id: json['id'] as int,
203203
message: Message.fromJson({
204204
...json['message'] as Map<String, dynamic>,
205-
'flags':
206-
(json['flags'] as List<dynamic>).map((e) => e as String).toList(),
205+
'flags': (json['flags'] as List<dynamic>).map((e) => e as String).toList(),
207206
}),
208207
);
209208

lib/api/model/model.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class User {
8787
return (value != null && value.isNotEmpty) ? value : null;
8888
}
8989

90-
static bool? _readIsSystemBot(Map json, String key) =>
91-
json[key] ?? json['is_cross_realm_bot'];
90+
static bool? _readIsSystemBot(Map json, String key) {
91+
return json[key] ?? json['is_cross_realm_bot'];
92+
}
9293

9394
User({
9495
required this.userId,

lib/model/content.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ final _emojiClassRegexp = RegExp(r"^emoji(-[0-9a-f]+)?$");
226226

227227
InlineContentNode parseInlineContent(dom.Node node) {
228228
final debugHtmlNode = kDebugMode ? node : null;
229-
InlineContentNode unimplemented() =>
230-
UnimplementedInlineContentNode(htmlNode: node);
229+
InlineContentNode unimplemented() => UnimplementedInlineContentNode(htmlNode: node);
231230

232231
if (node is dom.Text) {
233232
return TextNode(node.text, debugHtmlNode: debugHtmlNode);
@@ -239,8 +238,9 @@ InlineContentNode parseInlineContent(dom.Node node) {
239238
final element = node;
240239
final localName = element.localName;
241240
final classes = element.classes;
242-
List<InlineContentNode> nodes() =>
243-
element.nodes.map(parseInlineContent).toList(growable: false);
241+
List<InlineContentNode> nodes() {
242+
return element.nodes.map(parseInlineContent).toList(growable: false);
243+
}
244244

245245
if (localName == 'br' && classes.isEmpty) {
246246
return LineBreakInlineNode(debugHtmlNode: debugHtmlNode);
@@ -410,8 +410,9 @@ BlockContentNode parseBlockContent(dom.Node node) {
410410
final localName = element.localName;
411411
final classes = element.classes;
412412
List<BlockContentNode> blockNodes() => parseBlockContentList(element.nodes);
413-
List<InlineContentNode> inlineNodes() =>
414-
element.nodes.map(parseInlineContent).toList(growable: false);
413+
List<InlineContentNode> inlineNodes() {
414+
return element.nodes.map(parseInlineContent).toList(growable: false);
415+
}
415416

416417
if (localName == 'br' && classes.isEmpty) {
417418
return LineBreakNode(debugHtmlNode: debugHtmlNode);
@@ -489,8 +490,7 @@ List<BlockContentNode> parseImplicitParagraphBlockContentList(dom.NodeList nodes
489490
void consumeParagraph() {
490491
result.add(ParagraphNode(
491492
wasImplicit: true,
492-
nodes:
493-
currentParagraph.map(parseInlineContent).toList(growable: false)));
493+
nodes: currentParagraph.map(parseInlineContent).toList(growable: false)));
494494
currentParagraph.clear();
495495
}
496496

lib/model/message_list.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ class MessageListView extends ChangeNotifier {
5757
assert(messages.isEmpty);
5858
assert(contents.isEmpty);
5959
// TODO schedule all this in another isolate
60-
final result =
61-
await getMessages(store.connection, numBefore: 100, numAfter: 10);
60+
final result = await getMessages(store.connection,
61+
numBefore: 100,
62+
numAfter: 10,
63+
);
6264
messages.addAll(result.messages);
6365
contents.addAll(_contentsOfMessages(result.messages));
6466
_fetched = true;
@@ -92,8 +94,7 @@ class MessageListView extends ChangeNotifier {
9294
notifyListeners();
9395
}
9496

95-
static Iterable<ZulipContent> _contentsOfMessages(
96-
Iterable<Message> messages) {
97+
static Iterable<ZulipContent> _contentsOfMessages(Iterable<Message> messages) {
9798
// This will get more complicated to handle the ways that messages interact
9899
// with the display of neighboring messages: sender headings,
99100
// recipient headings, and date separators.

lib/model/store.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class PerAccountStore extends ChangeNotifier {
149149
required this.connection,
150150
required InitialSnapshot initialSnapshot,
151151
}) : zulipVersion = initialSnapshot.zulipVersion,
152-
users = Map.fromEntries(initialSnapshot.realmUsers
152+
users = Map.fromEntries(
153+
initialSnapshot.realmUsers
153154
.followedBy(initialSnapshot.realmNonActiveUsers)
154155
.followedBy(initialSnapshot.crossRealmBots)
155156
.map((user) => MapEntry(user.userId, user))),

lib/widgets/compose_box.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ Future<void> _uploadFiles({
250250
context: context,
251251
title: 'File(s) too large',
252252
message:
253-
'${tooLargeFiles.length} file(s) are larger than the server\'s limit of ${store.maxFileUploadSizeMib} MiB and will not be uploaded:\n\n$listMessage');
253+
'${tooLargeFiles.length} file(s) are larger than the server\'s limit'
254+
' of ${store.maxFileUploadSizeMib} MiB and will not be uploaded:'
255+
'\n\n$listMessage');
254256
}
255257

256258
final List<(int, _File)> uploadsInProgress = [];
@@ -320,7 +322,10 @@ abstract class _AttachUploadsButton extends StatelessWidget {
320322

321323
@override
322324
Widget build(BuildContext context) {
323-
return IconButton(icon: Icon(icon), tooltip: tooltip, onPressed: () => _handlePress(context));
325+
return IconButton(
326+
icon: Icon(icon),
327+
tooltip: tooltip,
328+
onPressed: () => _handlePress(context));
324329
}
325330
}
326331

lib/widgets/content.dart

+5-8
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class BlockContentNodeWidget extends StatelessWidget {
9797
border: Border(
9898
left: BorderSide(
9999
width: 5,
100-
color: const HSLColor.fromAHSL(1, 0, 0, 0.87)
101-
.toColor()))),
100+
color: const HSLColor.fromAHSL(1, 0, 0, 0.87).toColor()))),
102101
child: BlockContentList(nodes: node.nodes)));
103102
} else if (node is CodeBlockNode) {
104103
return CodeBlock(node: node);
@@ -311,15 +310,13 @@ InlineSpan _buildInlineNode(InlineContentNode node) {
311310
return styled(node.nodes,
312311
TextStyle(color: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor()));
313312
} else if (node is UserMentionNode) {
314-
return WidgetSpan(
315-
alignment: PlaceholderAlignment.middle, child: UserMention(node: node));
313+
return WidgetSpan(alignment: PlaceholderAlignment.middle,
314+
child: UserMention(node: node));
316315
} else if (node is UnicodeEmojiNode) {
317-
return WidgetSpan(
318-
alignment: PlaceholderAlignment.middle,
316+
return WidgetSpan(alignment: PlaceholderAlignment.middle,
319317
child: MessageUnicodeEmoji(node: node));
320318
} else if (node is ImageEmojiNode) {
321-
return WidgetSpan(
322-
alignment: PlaceholderAlignment.middle,
319+
return WidgetSpan(alignment: PlaceholderAlignment.middle,
323320
child: MessageImageEmoji(node: node));
324321
} else if (node is UnimplementedInlineContentNode) {
325322
return _errorUnimplemented(node);

lib/widgets/dialog.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ Widget _dialogActionText(String text) {
1515
}
1616

1717
// TODO(i18n): title, message, and action-button text
18-
void showErrorDialog({required BuildContext context, required String title, String? message}) {
18+
void showErrorDialog({
19+
required BuildContext context,
20+
required String title,
21+
String? message,
22+
}) {
1923
showDialog(
2024
context: context,
2125
builder: (BuildContext context) => AlertDialog(
@@ -35,7 +39,9 @@ void showSuggestedActionDialog({
3539
required String? actionButtonText,
3640
required VoidCallback onActionButtonPress,
3741
}) {
38-
showDialog(context: context, builder: (BuildContext context) => AlertDialog(
42+
showDialog(
43+
context: context,
44+
builder: (BuildContext context) => AlertDialog(
3945
title: Text(title),
4046
content: SingleChildScrollView(child: Text(message)),
4147
actions: [

lib/widgets/message_list.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'sticky_header.dart';
1313
import 'store.dart';
1414

1515
class MessageList extends StatefulWidget {
16-
const MessageList({Key? key}) : super(key: key);
16+
const MessageList({super.key});
1717

1818
@override
1919
State<StatefulWidget> createState() => _MessageListState();
@@ -212,8 +212,7 @@ class StreamTopicRecipientHeader extends StatelessWidget {
212212
RecipientHeaderChevronContainer(
213213
color: streamColor,
214214
// TODO globe/lock icons for web-public and private streams
215-
child:
216-
Text(streamName, style: TextStyle(color: contrastingColor))),
215+
child: Text(streamName, style: TextStyle(color: contrastingColor))),
217216
Expanded(
218217
child: Padding(
219218
// Web has padding 9, 3, 3, 2 here; but 5px is the chevron.
@@ -229,8 +228,7 @@ class StreamTopicRecipientHeader extends StatelessWidget {
229228
}
230229
}
231230

232-
final _kStreamMessageBorderColor =
233-
const HSLColor.fromAHSL(1, 0, 0, 0.88).toColor();
231+
final _kStreamMessageBorderColor = const HSLColor.fromAHSL(1, 0, 0, 0.88).toColor();
234232

235233
class PmRecipientHeader extends StatelessWidget {
236234
const PmRecipientHeader({super.key, required this.message});

lib/widgets/sticky_header.dart

+14-13
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ class RenderSliverStickyHeaderList extends RenderSliverList {
194194

195195
double childScrollOffset;
196196
if (innerChild.direction == constraints.axisDirection) {
197-
childScrollOffset =
198-
math.max(0.0, scrollOffset - parentData.layoutOffset!);
197+
childScrollOffset = math.max(0.0,
198+
scrollOffset - parentData.layoutOffset!);
199199
} else {
200200
final childEndOffset =
201201
parentData.layoutOffset! + child.size.onAxis(constraints.axis);
202202
// TODO should this be our layoutExtent or paintExtent, or what?
203-
childScrollOffset = math.max(
204-
0.0, childEndOffset - (scrollOffset + geometry!.layoutExtent));
203+
childScrollOffset = math.max(0.0,
204+
childEndOffset - (scrollOffset + geometry!.layoutExtent));
205205
}
206206
innerChild.provideScrollPosition(childScrollOffset);
207207
}
@@ -211,11 +211,12 @@ class RenderSliverStickyHeaderList extends RenderSliverList {
211211
enum StickyHeaderSlot { header, content }
212212

213213
class StickyHeader extends SlottedMultiChildRenderObjectWidget<StickyHeaderSlot, RenderBox> {
214-
const StickyHeader(
215-
{super.key,
214+
const StickyHeader({
215+
super.key,
216216
this.direction = AxisDirection.down,
217217
this.header,
218-
this.content});
218+
this.content,
219+
});
219220

220221
final AxisDirection direction;
221222
final Widget? header;
@@ -241,8 +242,7 @@ class StickyHeader extends SlottedMultiChildRenderObjectWidget<StickyHeaderSlot,
241242
}
242243
}
243244

244-
class RenderStickyHeader extends RenderBox
245-
with SlottedContainerRenderObjectMixin<StickyHeaderSlot, RenderBox> {
245+
class RenderStickyHeader extends RenderBox with SlottedContainerRenderObjectMixin<StickyHeaderSlot, RenderBox> {
246246
RenderStickyHeader({required AxisDirection direction})
247247
: _direction = direction;
248248

@@ -260,8 +260,10 @@ class RenderStickyHeader extends RenderBox
260260
}
261261

262262
@override
263-
Iterable<RenderBox> get children =>
264-
[if (_header != null) _header!, if (_content != null) _content!];
263+
Iterable<RenderBox> get children => [
264+
if (_header != null) _header!,
265+
if (_content != null) _content!,
266+
];
265267

266268
double? _slackSize;
267269

@@ -351,8 +353,7 @@ class RenderStickyHeader extends RenderBox
351353
return false;
352354
}
353355

354-
BoxParentData _parentData(RenderBox child) =>
355-
child.parentData! as BoxParentData;
356+
BoxParentData _parentData(RenderBox child) => child.parentData! as BoxParentData;
356357
}
357358

358359
Size sizeOn(Axis axis, {double main = 0, double cross = 0}) {

lib/widgets/store.dart

+15-12
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class GlobalStoreWidget extends StatefulWidget {
3838
/// * [PerAccountStoreWidget.of], for the user's data associated with a
3939
/// particular Zulip account.
4040
static GlobalStore of(BuildContext context) {
41-
final widget = context
42-
.dependOnInheritedWidgetOfExactType<_GlobalStoreInheritedWidget>();
41+
final widget = context.dependOnInheritedWidgetOfExactType<_GlobalStoreInheritedWidget>();
4342
assert(widget != null, 'No GlobalStoreWidget ancestor');
4443
return widget!.store;
4544
}
@@ -75,9 +74,10 @@ class _GlobalStoreWidgetState extends State<GlobalStoreWidget> {
7574
// a [StatefulWidget] to get hold of the store, and an [InheritedWidget] to
7675
// provide it to descendants, and one widget can't be both of those.
7776
class _GlobalStoreInheritedWidget extends InheritedNotifier<GlobalStore> {
78-
const _GlobalStoreInheritedWidget(
79-
{required GlobalStore store, required super.child})
80-
: super(notifier: store);
77+
const _GlobalStoreInheritedWidget({
78+
required GlobalStore store,
79+
required super.child,
80+
}) : super(notifier: store);
8181

8282
GlobalStore get store => notifier!;
8383

@@ -103,8 +103,11 @@ class _GlobalStoreInheritedWidget extends InheritedNotifier<GlobalStore> {
103103
/// * [GlobalStoreWidget], for the app's data beyond that of a
104104
/// particular account.
105105
class PerAccountStoreWidget extends StatefulWidget {
106-
const PerAccountStoreWidget(
107-
{super.key, required this.accountId, required this.child});
106+
const PerAccountStoreWidget({
107+
super.key,
108+
required this.accountId,
109+
required this.child,
110+
});
108111

109112
final int accountId;
110113
final Widget child;
@@ -137,8 +140,7 @@ class PerAccountStoreWidget extends StatefulWidget {
137140
/// particular account.
138141
/// * [InheritedNotifier], which provides the "dependency" mechanism.
139142
static PerAccountStore of(BuildContext context) {
140-
final widget = context
141-
.dependOnInheritedWidgetOfExactType<_PerAccountStoreInheritedWidget>();
143+
final widget = context.dependOnInheritedWidgetOfExactType<_PerAccountStoreInheritedWidget>();
142144
assert(widget != null, 'No PerAccountStoreWidget ancestor');
143145
return widget!.store;
144146
}
@@ -223,9 +225,10 @@ class _PerAccountStoreWidgetState extends State<PerAccountStoreWidget> {
223225
// [StatefulWidget] to get hold of the store, and an [InheritedWidget] to
224226
// provide it to descendants, and one widget can't be both of those.
225227
class _PerAccountStoreInheritedWidget extends InheritedNotifier<PerAccountStore> {
226-
const _PerAccountStoreInheritedWidget(
227-
{required PerAccountStore store, required super.child})
228-
: super(notifier: store);
228+
const _PerAccountStoreInheritedWidget({
229+
required PerAccountStore store,
230+
required super.child,
231+
}) : super(notifier: store);
229232

230233
PerAccountStore get store => notifier!;
231234

0 commit comments

Comments
 (0)