Skip to content

[flutter_markdown] Support wasm #6168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/flutter_markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.20+1

* Updates minimum supported SDK version to Flutter 3.19.

## 0.6.20

* Adds `textScaler` to `MarkdownStyleSheet`, and deprecates `textScaleFactor`.
Expand Down
27 changes: 12 additions & 15 deletions packages/flutter_markdown/lib/src/_functions_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:html'; // ignore: avoid_web_libraries_in_flutter
import 'dart:js_interop';

import 'package:flutter/cupertino.dart' show CupertinoTheme;
import 'package:flutter/material.dart' show Theme;
Expand Down Expand Up @@ -50,20 +50,14 @@ final MarkdownStyleSheet Function(BuildContext, MarkdownStyleSheetBaseTheme?)
BuildContext context,
MarkdownStyleSheetBaseTheme? baseTheme,
) {
MarkdownStyleSheet result;
switch (baseTheme) {
case MarkdownStyleSheetBaseTheme.platform:
final String userAgent = window.navigator.userAgent;
result = userAgent.contains('Mac OS X')
? MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context))
: MarkdownStyleSheet.fromTheme(Theme.of(context));
case MarkdownStyleSheetBaseTheme.cupertino:
result =
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context));
case MarkdownStyleSheetBaseTheme.material:
default: // ignore: no_default_cases
result = MarkdownStyleSheet.fromTheme(Theme.of(context));
}
final MarkdownStyleSheet result = switch (baseTheme) {
MarkdownStyleSheetBaseTheme.platform
when _userAgent.toDart.contains('Mac OS X') =>
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
MarkdownStyleSheetBaseTheme.cupertino =>
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
_ => MarkdownStyleSheet.fromTheme(Theme.of(context)),
};

return result.copyWith(
textScaler: MediaQuery.textScalerOf(context),
Expand All @@ -84,3 +78,6 @@ Widget _handleDataSchemeUri(
}
return const SizedBox();
}

@JS('window.navigator.userAgent')
external JSString get _userAgent;
5 changes: 1 addition & 4 deletions packages/flutter_markdown/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: unnecessary_import, see https://github.com/flutter/flutter/pull/138881
import 'dart:ui';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:markdown/markdown.dart' as md;

import '_functions_io.dart' if (dart.library.html) '_functions_web.dart';
import '_functions_io.dart' if (dart.library.js_interop) '_functions_web.dart';
import 'style_sheet.dart';
import 'widget.dart';

Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_markdown/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: A Markdown renderer for Flutter. Create rich text output,
formatted with simple Markdown tags.
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
version: 0.6.20
version: 0.6.20+1

environment:
sdk: ^3.2.0
flutter: ">=3.16.0"
sdk: ^3.3.0
flutter: ">=3.19.0"

dependencies:
flutter:
Expand Down