Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 17 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,8 @@
// 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 'dart:js_interop_unsafe';

import 'package:flutter/cupertino.dart' show CupertinoTheme;
import 'package:flutter/material.dart' show Theme;
Expand Down Expand Up @@ -50,20 +51,15 @@ 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.contains('Mac OS X') =>
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
MarkdownStyleSheetBaseTheme.cupertino =>
MarkdownStyleSheet.fromCupertinoTheme(CupertinoTheme.of(context)),
MarkdownStyleSheetBaseTheme.material ||
_ =>
MarkdownStyleSheet.fromTheme(Theme.of(context)),
};

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

final String _userAgent = globalContext
.getProperty<JSObject>('window'.toJS)
.getProperty<JSObject>('navigator'.toJS)
.getProperty<JSString>('userAgent'.toJS)
.toDart;
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