Skip to content

Commit ed046de

Browse files
authored
[flutter_markdown] Support wasm (#6168)
Drop usage of dart:html
1 parent 9c15ec5 commit ed046de

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

packages/flutter_markdown/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.20+1
2+
3+
* Updates minimum supported SDK version to Flutter 3.19.
4+
15
## 0.6.20
26

37
* Adds `textScaler` to `MarkdownStyleSheet`, and deprecates `textScaleFactor`.

packages/flutter_markdown/lib/src/_functions_web.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:html'; // ignore: avoid_web_libraries_in_flutter
5+
import 'dart:js_interop';
66

77
import 'package:flutter/cupertino.dart' show CupertinoTheme;
88
import 'package:flutter/material.dart' show Theme;
@@ -50,20 +50,14 @@ final MarkdownStyleSheet Function(BuildContext, MarkdownStyleSheetBaseTheme?)
5050
BuildContext context,
5151
MarkdownStyleSheetBaseTheme? baseTheme,
5252
) {
53-
MarkdownStyleSheet result;
54-
switch (baseTheme) {
55-
case MarkdownStyleSheetBaseTheme.platform:
56-
final String userAgent = window.navigator.userAgent;
57-
result = userAgent.contains('Mac OS X')
58-
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
59-
: MarkdownStyleSheet.fromTheme(Theme.of(context));
60-
case MarkdownStyleSheetBaseTheme.cupertino:
61-
result =
62-
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
63-
case MarkdownStyleSheetBaseTheme.material:
64-
default: // ignore: no_default_cases
65-
result = MarkdownStyleSheet.fromTheme(Theme.of(context));
66-
}
53+
final MarkdownStyleSheet result = switch (baseTheme) {
54+
MarkdownStyleSheetBaseTheme.platform
55+
when _userAgent.toDart.contains('Mac OS X') =>
56+
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
57+
MarkdownStyleSheetBaseTheme.cupertino =>
58+
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
59+
_ => MarkdownStyleSheet.fromTheme(Theme.of(context)),
60+
};
6761

6862
return result.copyWith(
6963
textScaler: MediaQuery.textScalerOf(context),
@@ -84,3 +78,6 @@ Widget _handleDataSchemeUri(
8478
}
8579
return const SizedBox();
8680
}
81+
82+
@JS('window.navigator.userAgent')
83+
external JSString get _userAgent;

packages/flutter_markdown/lib/src/builder.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// ignore: unnecessary_import, see https://github.com/flutter/flutter/pull/138881
6-
import 'dart:ui';
7-
85
import 'package:flutter/gestures.dart';
96
import 'package:flutter/material.dart';
107
import 'package:markdown/markdown.dart' as md;
118

12-
import '_functions_io.dart' if (dart.library.html) '_functions_web.dart';
9+
import '_functions_io.dart' if (dart.library.js_interop) '_functions_web.dart';
1310
import 'style_sheet.dart';
1411
import 'widget.dart';
1512

packages/flutter_markdown/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ description: A Markdown renderer for Flutter. Create rich text output,
44
formatted with simple Markdown tags.
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
7-
version: 0.6.20
7+
version: 0.6.20+1
88

99
environment:
10-
sdk: ^3.2.0
11-
flutter: ">=3.16.0"
10+
sdk: ^3.3.0
11+
flutter: ">=3.19.0"
1212

1313
dependencies:
1414
flutter:

0 commit comments

Comments
 (0)