Skip to content

Commit 36c25ec

Browse files
committed
fmt [nfc]: Fix basic formatting from early-prototype code
There's a set of formatting patterns we've pretty well settled into at this point. But there's still some swathes of code that don't adhere to them -- mainly from the early prototype period, when we were just figuring out how to write Dart and how we wanted the code to look. So, here's a quick sweep through our code to apply our current patterns more uniformly. The major one is indentation: we use 2-space indents throughout, rather than 4-space. This diff therefore looks a lot smaller with `git diff -b`. The other one packaged into this same commit is how we close widgets: like `)));` at the end of the innermost child, rather than like `),\n),\n);`. (For other kinds of function calls we use either form, and I've largely left those in place.)
1 parent 36dc0cb commit 36c25ec

21 files changed

+525
-549
lines changed

lib/api/core.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ApiConnection {
104104
Future<T> get<T>(String routeName, T Function(Map<String, dynamic>) fromJson,
105105
String path, Map<String, dynamic>? params) async {
106106
final url = realmUrl.replace(
107-
path: "/api/v1/$path", queryParameters: encodeParameters(params));
107+
path: "/api/v1/$path", queryParameters: encodeParameters(params));
108108
final request = http.Request('GET', url);
109109
return send(routeName, fromJson, request);
110110
}
@@ -167,5 +167,5 @@ Map<String, String> authHeader({required String email, required String apiKey})
167167

168168
Map<String, String>? encodeParameters(Map<String, dynamic>? params) {
169169
return params?.map((k, v) =>
170-
MapEntry(k, v is RawParameter ? v.value : jsonEncode(v)));
170+
MapEntry(k, v is RawParameter ? v.value : jsonEncode(v)));
171171
}

lib/api/model/events.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UnexpectedEvent extends Event {
4545
UnexpectedEvent({required super.id, required this.json});
4646

4747
factory UnexpectedEvent.fromJson(Map<String, dynamic> json) =>
48-
UnexpectedEvent(id: json['id'] as int, json: json);
48+
UnexpectedEvent(id: json['id'] as int, json: json);
4949

5050
@override
5151
Map<String, dynamic> toJson() => json;
@@ -63,7 +63,7 @@ class AlertWordsEvent extends Event {
6363
AlertWordsEvent({required super.id, required this.alertWords});
6464

6565
factory AlertWordsEvent.fromJson(Map<String, dynamic> json) =>
66-
_$AlertWordsEventFromJson(json);
66+
_$AlertWordsEventFromJson(json);
6767

6868
@override
6969
Map<String, dynamic> toJson() => _$AlertWordsEventToJson(this);
@@ -199,12 +199,12 @@ class MessageEvent extends Event {
199199
MessageEvent({required super.id, required this.message});
200200

201201
factory MessageEvent.fromJson(Map<String, dynamic> json) => MessageEvent(
202-
id: json['id'] as int,
203-
message: Message.fromJson({
204-
...json['message'] as Map<String, dynamic>,
205-
'flags':
206-
(json['flags'] as List<dynamic>).map((e) => e as String).toList(),
207-
}),
202+
id: json['id'] as int,
203+
message: Message.fromJson({
204+
...json['message'] as Map<String, dynamic>,
205+
'flags':
206+
(json['flags'] as List<dynamic>).map((e) => e as String).toList(),
207+
}),
208208
);
209209

210210
@override
@@ -225,7 +225,7 @@ class HeartbeatEvent extends Event {
225225
HeartbeatEvent({required super.id});
226226

227227
factory HeartbeatEvent.fromJson(Map<String, dynamic> json) =>
228-
_$HeartbeatEventFromJson(json);
228+
_$HeartbeatEventFromJson(json);
229229

230230
@override
231231
Map<String, dynamic> toJson() => _$HeartbeatEventToJson(this);

lib/api/model/initial_snapshot.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class InitialSnapshot {
6666
});
6767

6868
factory InitialSnapshot.fromJson(Map<String, dynamic> json) =>
69-
_$InitialSnapshotFromJson(json);
69+
_$InitialSnapshotFromJson(json);
7070

7171
Map<String, dynamic> toJson() => _$InitialSnapshotToJson(this);
7272
}

lib/api/model/model.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CustomProfileField {
2626
});
2727

2828
factory CustomProfileField.fromJson(Map<String, dynamic> json) =>
29-
_$CustomProfileFieldFromJson(json);
29+
_$CustomProfileFieldFromJson(json);
3030

3131
Map<String, dynamic> toJson() => _$CustomProfileFieldToJson(this);
3232
}
@@ -88,7 +88,7 @@ class User {
8888
}
8989

9090
static bool? _readIsSystemBot(Map json, String key) =>
91-
json[key] ?? json['is_cross_realm_bot'];
91+
json[key] ?? json['is_cross_realm_bot'];
9292

9393
User({
9494
required this.userId,
@@ -183,7 +183,7 @@ class Subscription {
183183
});
184184

185185
factory Subscription.fromJson(Map<String, dynamic> json) =>
186-
_$SubscriptionFromJson(json);
186+
_$SubscriptionFromJson(json);
187187

188188
Map<String, dynamic> toJson() => _$SubscriptionToJson(this);
189189
}
@@ -281,7 +281,7 @@ class StreamMessage extends Message {
281281
});
282282

283283
factory StreamMessage.fromJson(Map<String, dynamic> json) =>
284-
_$StreamMessageFromJson(json);
284+
_$StreamMessageFromJson(json);
285285

286286
@override
287287
Map<String, dynamic> toJson() => _$StreamMessageToJson(this);
@@ -299,7 +299,7 @@ class PmRecipient {
299299
PmRecipient({required this.id, required this.email, required this.fullName});
300300

301301
factory PmRecipient.fromJson(Map<String, dynamic> json) =>
302-
_$PmRecipientFromJson(json);
302+
_$PmRecipientFromJson(json);
303303

304304
Map<String, dynamic> toJson() => _$PmRecipientToJson(this);
305305
}
@@ -334,7 +334,7 @@ class PmMessage extends Message {
334334
});
335335

336336
factory PmMessage.fromJson(Map<String, dynamic> json) =>
337-
_$PmMessageFromJson(json);
337+
_$PmMessageFromJson(json);
338338

339339
@override
340340
Map<String, dynamic> toJson() => _$PmMessageToJson(this);

lib/api/route/events.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GetEventsResult {
4444
});
4545

4646
factory GetEventsResult.fromJson(Map<String, dynamic> json) =>
47-
_$GetEventsResultFromJson(json);
47+
_$GetEventsResultFromJson(json);
4848

4949
Map<String, dynamic> toJson() => _$GetEventsResultToJson(this);
5050
}

lib/api/route/messages.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SendMessageResult {
8989
});
9090

9191
factory SendMessageResult.fromJson(Map<String, dynamic> json) =>
92-
_$SendMessageResultFromJson(json);
92+
_$SendMessageResultFromJson(json);
9393

9494
Map<String, dynamic> toJson() => _$SendMessageResultToJson(this);
9595
}
@@ -114,7 +114,7 @@ class UploadFileResult {
114114
});
115115

116116
factory UploadFileResult.fromJson(Map<String, dynamic> json) =>
117-
_$UploadFileResultFromJson(json);
117+
_$UploadFileResultFromJson(json);
118118

119119
Map<String, dynamic> toJson() => _$UploadFileResultToJson(this);
120120
}

lib/model/content.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LineBreakNode extends BlockContentNode {
7575
// See also [parseImplicitParagraphBlockContentList].
7676
class ParagraphNode extends BlockContentNode {
7777
const ParagraphNode(
78-
{super.debugHtmlNode, this.wasImplicit = false, required this.nodes});
78+
{super.debugHtmlNode, this.wasImplicit = false, required this.nodes});
7979

8080
/// True when there was no corresponding `p` element in the original HTML.
8181
final bool wasImplicit;
@@ -227,7 +227,7 @@ final _emojiClassRegexp = RegExp(r"^emoji(-[0-9a-f]+)?$");
227227
InlineContentNode parseInlineContent(dom.Node node) {
228228
final debugHtmlNode = kDebugMode ? node : null;
229229
InlineContentNode unimplemented() =>
230-
UnimplementedInlineContentNode(htmlNode: node);
230+
UnimplementedInlineContentNode(htmlNode: node);
231231

232232
if (node is dom.Text) {
233233
return TextNode(node.text, debugHtmlNode: debugHtmlNode);
@@ -240,7 +240,7 @@ InlineContentNode parseInlineContent(dom.Node node) {
240240
final localName = element.localName;
241241
final classes = element.classes;
242242
List<InlineContentNode> nodes() =>
243-
element.nodes.map(parseInlineContent).toList(growable: false);
243+
element.nodes.map(parseInlineContent).toList(growable: false);
244244

245245
if (localName == 'br' && classes.isEmpty) {
246246
return LineBreakInlineNode(debugHtmlNode: debugHtmlNode);
@@ -317,9 +317,9 @@ BlockContentNode parseListNode(dom.Element element) {
317317

318318
BlockContentNode parseCodeBlock(dom.Element divElement) {
319319
final mainElement = () {
320-
assert(divElement.localName == 'div' &&
321-
divElement.classes.length == 1 &&
322-
divElement.classes.contains("codehilite"));
320+
assert(divElement.localName == 'div'
321+
&& divElement.classes.length == 1
322+
&& divElement.classes.contains("codehilite"));
323323

324324
if (divElement.nodes.length != 1) return null;
325325
final child = divElement.nodes[0];
@@ -329,9 +329,9 @@ BlockContentNode parseCodeBlock(dom.Element divElement) {
329329
if (child.nodes.length > 2) return null;
330330
if (child.nodes.length == 2) {
331331
final first = child.nodes[0];
332-
if (first is! dom.Element ||
333-
first.localName != 'span' ||
334-
first.nodes.isNotEmpty) return null;
332+
if (first is! dom.Element
333+
|| first.localName != 'span'
334+
|| first.nodes.isNotEmpty) return null;
335335
}
336336
final grandchild = child.nodes[child.nodes.length - 1];
337337
if (grandchild is! dom.Element) return null;
@@ -371,8 +371,8 @@ BlockContentNode parseCodeBlock(dom.Element divElement) {
371371
BlockContentNode parseImageNode(dom.Element divElement) {
372372
final imgElement = () {
373373
assert(divElement.localName == 'div'
374-
&& divElement.classes.length == 1
375-
&& divElement.classes.contains('message_inline_image'));
374+
&& divElement.classes.length == 1
375+
&& divElement.classes.contains('message_inline_image'));
376376

377377
if (divElement.nodes.length != 1) return null;
378378
final child = divElement.nodes[0];
@@ -411,7 +411,7 @@ BlockContentNode parseBlockContent(dom.Node node) {
411411
final classes = element.classes;
412412
List<BlockContentNode> blockNodes() => parseBlockContentList(element.nodes);
413413
List<InlineContentNode> inlineNodes() =>
414-
element.nodes.map(parseInlineContent).toList(growable: false);
414+
element.nodes.map(parseInlineContent).toList(growable: false);
415415

416416
if (localName == 'br' && classes.isEmpty) {
417417
return LineBreakNode(debugHtmlNode: debugHtmlNode);
@@ -437,7 +437,7 @@ BlockContentNode parseBlockContent(dom.Node node) {
437437
if (headingLevel == HeadingLevel.h6 && classes.isEmpty) {
438438
// TODO handle h1, h2, h3, h4, h5
439439
return HeadingNode(
440-
headingLevel!, inlineNodes(), debugHtmlNode: debugHtmlNode);
440+
headingLevel!, inlineNodes(), debugHtmlNode: debugHtmlNode);
441441
}
442442

443443
if (localName == 'blockquote' && classes.isEmpty) {
@@ -488,9 +488,9 @@ List<BlockContentNode> parseImplicitParagraphBlockContentList(dom.NodeList nodes
488488
final List<dom.Node> currentParagraph = [];
489489
void consumeParagraph() {
490490
result.add(ParagraphNode(
491-
wasImplicit: true,
492-
nodes:
493-
currentParagraph.map(parseInlineContent).toList(growable: false)));
491+
wasImplicit: true,
492+
nodes:
493+
currentParagraph.map(parseInlineContent).toList(growable: false)));
494494
currentParagraph.clear();
495495
}
496496

lib/model/message_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MessageListView extends ChangeNotifier {
5858
assert(contents.isEmpty);
5959
// TODO schedule all this in another isolate
6060
final result =
61-
await getMessages(store.connection, numBefore: 100, numAfter: 10);
61+
await getMessages(store.connection, numBefore: 100, numAfter: 10);
6262
messages.addAll(result.messages);
6363
contents.addAll(_contentsOfMessages(result.messages));
6464
_fetched = true;

lib/model/store.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export 'database.dart' show Account, AccountsCompanion;
3838
/// we use outside of tests.
3939
abstract class GlobalStore extends ChangeNotifier {
4040
GlobalStore({required Map<int, Account> accounts})
41-
: _accounts = accounts;
41+
: _accounts = accounts;
4242

4343
/// A cache of the [Accounts] table in the underlying data store.
4444
final Map<int, Account> _accounts;
@@ -148,14 +148,14 @@ class PerAccountStore extends ChangeNotifier {
148148
required this.account,
149149
required this.connection,
150150
required InitialSnapshot initialSnapshot,
151-
}) : zulipVersion = initialSnapshot.zulipVersion,
152-
users = Map.fromEntries(initialSnapshot.realmUsers
153-
.followedBy(initialSnapshot.realmNonActiveUsers)
154-
.followedBy(initialSnapshot.crossRealmBots)
155-
.map((user) => MapEntry(user.userId, user))),
156-
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
157-
(subscription) => MapEntry(subscription.streamId, subscription))),
158-
maxFileUploadSizeMib = initialSnapshot.maxFileUploadSizeMib;
151+
}) : zulipVersion = initialSnapshot.zulipVersion,
152+
users = Map.fromEntries(initialSnapshot.realmUsers
153+
.followedBy(initialSnapshot.realmNonActiveUsers)
154+
.followedBy(initialSnapshot.crossRealmBots)
155+
.map((user) => MapEntry(user.userId, user))),
156+
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
157+
(subscription) => MapEntry(subscription.streamId, subscription))),
158+
maxFileUploadSizeMib = initialSnapshot.maxFileUploadSizeMib;
159159

160160
final Account account;
161161
final ApiConnection connection;
@@ -324,13 +324,13 @@ class LivePerAccountStore extends PerAccountStore {
324324
required super.account,
325325
required super.connection,
326326
required super.initialSnapshot,
327-
}) : queueId = initialSnapshot.queueId ?? (() {
328-
// The queueId is optional in the type, but should only be missing in the
329-
// case of unauthenticated access to a web-public realm. We authenticated.
330-
throw Exception("bad initial snapshot: missing queueId");
331-
})(),
332-
lastEventId = initialSnapshot.lastEventId,
333-
super.fromInitialSnapshot();
327+
}) : queueId = initialSnapshot.queueId ?? (() {
328+
// The queueId is optional in the type, but should only be missing in the
329+
// case of unauthenticated access to a web-public realm. We authenticated.
330+
throw Exception("bad initial snapshot: missing queueId");
331+
})(),
332+
lastEventId = initialSnapshot.lastEventId,
333+
super.fromInitialSnapshot();
334334

335335
/// Load the user's data from the server, and start an event queue going.
336336
///
@@ -360,7 +360,7 @@ class LivePerAccountStore extends PerAccountStore {
360360
void poll() async {
361361
while (true) {
362362
final result = await getEvents(connection,
363-
queueId: queueId, lastEventId: lastEventId);
363+
queueId: queueId, lastEventId: lastEventId);
364364
// TODO handle errors on get-events; retry with backoff
365365
// TODO abort long-poll and close ApiConnection on [dispose]
366366
final events = result.events;

lib/widgets/action_sheet.dart

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,29 @@ void showMessageActionSheet({required BuildContext context, required Message mes
88
showDraggableScrollableModalBottomSheet(
99
context: context,
1010
builder: (BuildContext context) {
11-
return Column(
12-
children: [
13-
MenuItemButton(
14-
leadingIcon: Icon(Icons.adaptive.share),
15-
onPressed: () async {
16-
// Close the message action sheet; we're about to show the share
17-
// sheet. (We could do this after the sharing Future settles, but
18-
// on iOS I get impatient with how slowly our action sheet
19-
// dismisses in that case.)
20-
// TODO(#24): Fix iOS bug where this call causes the keyboard to
21-
// reopen (if it was open at the time of this
22-
// `showMessageActionSheet` call) and cover a large part of the
23-
// share sheet.
24-
Navigator.of(context).pop();
11+
return Column(children: [
12+
MenuItemButton(
13+
leadingIcon: Icon(Icons.adaptive.share),
14+
onPressed: () async {
15+
// Close the message action sheet; we're about to show the share
16+
// sheet. (We could do this after the sharing Future settles, but
17+
// on iOS I get impatient with how slowly our action sheet
18+
// dismisses in that case.)
19+
// TODO(#24): Fix iOS bug where this call causes the keyboard to
20+
// reopen (if it was open at the time of this
21+
// `showMessageActionSheet` call) and cover a large part of the
22+
// share sheet.
23+
Navigator.of(context).pop();
2524

26-
// TODO: to support iPads, we're asked to give a
27-
// `sharePositionOrigin` param, or risk crashing / hanging:
28-
// https://pub.dev/packages/share_plus#ipad
29-
// Perhaps a wart in the API; discussion:
30-
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
31-
// TODO: Share raw Markdown, not HTML
32-
await Share.shareWithResult(message.content);
33-
},
34-
child: const Text('Share'),
35-
),
36-
]
37-
);
25+
// TODO: to support iPads, we're asked to give a
26+
// `sharePositionOrigin` param, or risk crashing / hanging:
27+
// https://pub.dev/packages/share_plus#ipad
28+
// Perhaps a wart in the API; discussion:
29+
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
30+
// TODO: Share raw Markdown, not HTML
31+
await Share.shareWithResult(message.content);
32+
},
33+
child: const Text('Share')),
34+
]);
3835
});
3936
}

0 commit comments

Comments
 (0)