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
77import 'package:flutter/cupertino.dart' show CupertinoTheme;
88import '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;
0 commit comments