Skip to content

Commit 617a081

Browse files
committed
Switch from try/catch to firstWhereOrNull from 'collections'
1 parent 35ac32c commit 617a081

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/src/css_parser.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:ui';
22

3+
import 'package:collection/collection.dart';
34
import 'package:csslib/visitor.dart' as css;
45
import 'package:csslib/parser.dart' as cssparser;
56
import 'package:flutter/cupertino.dart';
@@ -72,12 +73,8 @@ Style declarationsToStyle(Map<String?, List<css.Expression>> declarations) {
7273
css.Expression? textDecorationColor;
7374
/// orElse: will not allow me to return null (even if the compiler says its okay, it errors on runtime).
7475
/// try/catch is a workaround for this.
75-
try {
76-
textDecorationColor = nullableList.firstWhere(
77-
(css.Expression? element) => element is css.HexColorTerm || element is css.FunctionTerm);
78-
} catch (e) {
79-
textDecorationColor = null;
80-
}
76+
textDecorationColor = nullableList.firstWhereOrNull(
77+
(element) => element is css.HexColorTerm || element is css.FunctionTerm);
8178
List<css.LiteralTerm?>? potentialStyles = value.whereType<css.LiteralTerm>().toList();
8279
/// List<css.LiteralTerm> might include other values than the ones we want for [textDecorationStyle], so make sure to remove those before passing it to [ExpressionMapping]
8380
potentialStyles.removeWhere((element) => element != null && element.text != "solid"

pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ dependencies:
3434
# Plugin for rendering MathML
3535
flutter_math_fork: ^0.3.0+1
3636

37+
# plugin for firstWhereOrNull extension on lists
38+
collection: ^1.15.0
39+
3740
flutter:
3841
sdk: flutter
3942

0 commit comments

Comments
 (0)