Skip to content

Commit

Permalink
fix(macos): black text color in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 3, 2022
1 parent 2bcf98a commit 8cf88e8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 36 deletions.
3 changes: 2 additions & 1 deletion lib/src/platform_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PlatformAlertDialog extends StatelessWidget with PlatformMixin<Widget> {
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
textStyle: PlatformTheme.of(context).textTheme!.body!,
child: getPlatformType(context),
);
}
Expand Down Expand Up @@ -84,7 +85,7 @@ Future<T?> showPlatformAlertDialog<T>(
required WidgetBuilder builder,
String? barrierLabel,
bool useRootNavigator = true,
bool barrierDismissible = true,
bool barrierDismissible = false,
RouteSettings? routeSettings,
Offset? anchorPoint,
Color? barrierColor,
Expand Down
39 changes: 22 additions & 17 deletions lib/src/platform_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: buildPlatformTheme,
builder: buildPlatformTheme(builder),
title: title,
onGenerateTitle: onGenerateTitle,
androidTheme: androidTheme,
Expand Down Expand Up @@ -179,19 +179,24 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
);
}

static Widget buildPlatformTheme(BuildContext context, Widget? child) {
final platformThemeData = PlatformThemeData.fromContext(context);
return PlatformTheme(
theme: platformThemeData,
child: IconTheme(
data: platformThemeData.iconTheme ?? Theme.of(context).iconTheme,
child: DefaultTextStyle(
style: platformThemeData.textTheme?.body ??
Theme.of(context).textTheme.bodyMedium!,
child: child ?? Container(),
static Widget Function(BuildContext context, Widget? child)
buildPlatformTheme(
Widget Function(BuildContext context, Widget? child)? builder,
) {
return (context, child) {
final platformThemeData = PlatformThemeData.fromContext(context);
return PlatformTheme(
theme: platformThemeData,
child: IconTheme(
data: platformThemeData.iconTheme ?? Theme.of(context).iconTheme,
child: DefaultTextStyle(
style: platformThemeData.textTheme?.body ??
Theme.of(context).textTheme.bodyMedium!,
child: builder?.call(context, child) ?? child ?? Container(),
),
),
),
);
);
};
}

@override
Expand All @@ -206,7 +211,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: buildPlatformTheme,
builder: buildPlatformTheme(builder),
title: title,
onGenerateTitle: onGenerateTitle,
theme: androidTheme,
Expand Down Expand Up @@ -251,7 +256,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: buildPlatformTheme,
builder: buildPlatformTheme(builder),
title: title,
onGenerateTitle: onGenerateTitle,
theme: iosTheme,
Expand Down Expand Up @@ -296,7 +301,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: buildPlatformTheme,
builder: buildPlatformTheme(builder),
title: title,
onGenerateTitle: onGenerateTitle,
theme: macosTheme,
Expand Down Expand Up @@ -337,7 +342,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: buildPlatformTheme,
builder: buildPlatformTheme(builder),
title: title,
onGenerateTitle: onGenerateTitle,
theme: windowsTheme,
Expand Down
1 change: 1 addition & 0 deletions lib/src/platform_popup_menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class PlatformPopupMenuButton<T> extends StatelessWidget
highlightColor: Colors.transparent,
),
child: Material(
textStyle: PlatformTheme.of(context).textTheme!.body!,
child: PopupMenuButton<T>(
itemBuilder: (context) {
return items.expandIndexed<PopupMenuEntry<T>>((i, e) {
Expand Down
53 changes: 43 additions & 10 deletions lib/src/platform_scaffold.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/platform_ui.dart';

class PlatformScaffold extends StatelessWidget {
Expand Down Expand Up @@ -64,21 +61,57 @@ class PlatformScaffold extends StatelessWidget {
return Scaffold(
extendBody: extendBody,
extendBodyBehindAppBar: extendBodyBehindAppBar,
appBar: appBar,
body: body,
floatingActionButton: floatingActionButton,
appBar: appBar != null
? PreferredSize(
preferredSize: appBar!.preferredSize,
child: DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: appBar!,
),
)
: null,
body: DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: body,
),
floatingActionButton: floatingActionButton != null
? DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: floatingActionButton!,
)
: null,
floatingActionButtonLocation: floatingActionButtonLocation,
floatingActionButtonAnimator: floatingActionButtonAnimator,
persistentFooterButtons: persistentFooterButtons,
persistentFooterAlignment: persistentFooterAlignment,
drawer: drawer,
drawer: drawer != null
? DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: drawer!,
)
: null,
onDrawerChanged: onDrawerChanged,
endDrawer: endDrawer,
endDrawer: endDrawer != null
? DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: endDrawer!,
)
: null,
onEndDrawerChanged: onEndDrawerChanged,
drawerScrimColor: drawerScrimColor,
backgroundColor: PlatformTheme.of(context).scaffoldBackgroundColor,
bottomNavigationBar: bottomNavigationBar,
bottomSheet: bottomSheet,
bottomNavigationBar: bottomNavigationBar != null
? DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: bottomNavigationBar!,
)
: null,
bottomSheet: bottomSheet != null
? DefaultTextStyle(
style: PlatformTextTheme.of(context).body!,
child: bottomSheet!,
)
: null,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
primary: primary,
drawerDragStartBehavior: drawerDragStartBehavior,
Expand Down
17 changes: 9 additions & 8 deletions lib/src/specific/cupertino_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'
MaterialState,
MaterialStateMouseCursor,
MaterialStateProperty;
import 'package:platform_ui/platform_ui.dart';
export 'package:flutter/material.dart' show ListTileTheme;

typedef RectCallback = Rect Function();
Expand Down Expand Up @@ -486,7 +487,7 @@ class CupertinoListTile extends StatelessWidget {
/// See [ListTile.autofocus].
final bool autofocus;

Color? _iconColor(BuildContext context, CupertinoThemeData theme,
Color? _iconColor(BuildContext context, PlatformThemeData theme,
ListTileThemeData tileTheme) {
if (!enabled) {
return CupertinoDynamicColor.resolve(
Expand All @@ -504,7 +505,7 @@ class CupertinoListTile extends StatelessWidget {
return null;
}

Color? _textColor(BuildContext context, CupertinoThemeData theme,
Color? _textColor(BuildContext context, PlatformThemeData theme,
ListTileThemeData tileTheme, Color? defaultColor) {
if (!enabled) {
return CupertinoDynamicColor.resolve(
Expand All @@ -526,28 +527,28 @@ class CupertinoListTile extends StatelessWidget {
return dense ?? tileTheme.dense ?? false;
}

TextStyle _titleTextStyle(BuildContext context, CupertinoThemeData theme,
TextStyle _titleTextStyle(BuildContext context, PlatformThemeData theme,
ListTileThemeData tileTheme) {
TextStyle style = theme.textTheme.textStyle;
TextStyle style = theme.textTheme!.body!;
final Color? color = _textColor(context, theme, tileTheme, style.color);
return _isDenseLayout(tileTheme)
? style.copyWith(fontSize: 13.0, color: color)
: style.copyWith(color: color);
}

TextStyle _subtitleTextStyle(BuildContext context, CupertinoThemeData theme,
TextStyle _subtitleTextStyle(BuildContext context, PlatformThemeData theme,
ListTileThemeData tileTheme) {
final TextStyle style = theme.textTheme.tabLabelTextStyle;
final TextStyle style = theme.textTheme!.caption!;
final Color? color =
_textColor(context, theme, tileTheme, theme.textTheme.textStyle.color);
_textColor(context, theme, tileTheme, theme.textTheme!.body!.color);
return _isDenseLayout(tileTheme)
? style.copyWith(color: color, fontSize: 12.0)
: style.copyWith(color: color);
}

@override
Widget build(BuildContext context) {
final CupertinoThemeData theme = CupertinoTheme.of(context);
final PlatformThemeData theme = PlatformTheme.of(context);
final ListTileThemeData tileTheme = ListTileTheme.of(context);

late IconThemeData iconThemeData;
Expand Down

0 comments on commit 8cf88e8

Please sign in to comment.