Skip to content

Commit aa5aecc

Browse files
authored
Copy of Flutter utility classes to make it simpler to later convert this code to Hummingbird. (#67)
* Copy of Flutter utility classes to make it simpler to write code with dart:html and convert to hummingbird later. There are no changes to these files other than stripping out portions of files irrelevant on the web.
1 parent 5abe232 commit aa5aecc

File tree

10 files changed

+6499
-0
lines changed

10 files changed

+6499
-0
lines changed

lib/ui/fake_flutter/assertions.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
part of 'fake_flutter.dart';
5+
6+
/// Error class used to report Flutter-specific assertion failures and
7+
/// contract violations.
8+
class FlutterError extends AssertionError {
9+
/// Creates a [FlutterError].
10+
///
11+
/// See [message] for details on the format that the message should
12+
/// take.
13+
///
14+
/// Include as much detail as possible in the full error message,
15+
/// including specifics about the state of the app that might be
16+
/// relevant to debugging the error.
17+
FlutterError(String message) : super(message);
18+
19+
/// The message associated with this error.
20+
///
21+
/// The message may have newlines in it. The first line should be a terse
22+
/// description of the error, e.g. "Incorrect GlobalKey usage" or "setState()
23+
/// or markNeedsBuild() called during build". Subsequent lines should contain
24+
/// substantial additional information, ideally sufficient to develop a
25+
/// correct solution to the problem.
26+
///
27+
/// In some cases, when a FlutterError is reported to the user, only the first
28+
/// line is included. For example, Flutter will typically only fully report
29+
/// the first exception at runtime, displaying only the first line of
30+
/// subsequent errors.
31+
///
32+
/// All sentences in the error should be correctly punctuated (i.e.,
33+
/// do end the error message with a period).
34+
@override
35+
String get message => super.message;
36+
37+
@override
38+
String toString() => message;
39+
}

lib/ui/fake_flutter/collections.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
library collections;
6+
7+
// TODO(ianh): These should be on the Set and List classes themselves.
8+
9+
/// Compares two sets for deep equality.
10+
///
11+
/// Returns true if the sets are both null, or if they are both non-null, have
12+
/// the same length, and contain the same members. Returns false otherwise.
13+
/// Order is not compared.
14+
///
15+
/// See also:
16+
///
17+
/// * [listEquals], which does something similar for lists.
18+
bool setEquals<T>(Set<T> a, Set<T> b) {
19+
if (a == null)
20+
return b == null;
21+
if (b == null || a.length != b.length)
22+
return false;
23+
for (T value in a) {
24+
if (!b.contains(value))
25+
return false;
26+
}
27+
return true;
28+
}
29+
30+
/// Compares two lists for deep equality.
31+
///
32+
/// Returns true if the lists are both null, or if they are both non-null, have
33+
/// the same length, and contain the same members in the same order. Returns
34+
/// false otherwise.
35+
///
36+
/// See also:
37+
///
38+
/// * [setEquals], which does something similar for sets.
39+
bool listEquals<T>(List<T> a, List<T> b) {
40+
if (a == null)
41+
return b == null;
42+
if (b == null || a.length != b.length)
43+
return false;
44+
for (int index = 0; index < a.length; index += 1) {
45+
if (a[index] != b[index])
46+
return false;
47+
}
48+
return true;
49+
}

0 commit comments

Comments
 (0)