43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../ui/adaptive/host.dart';
|
|
|
|
bool usesCupertinoControls(BuildContext context) =>
|
|
usesCupertinoHost(context) ||
|
|
Theme.of(context).platform == TargetPlatform.iOS;
|
|
|
|
Color settingsErrorColor(BuildContext context) => usesCupertinoControls(context)
|
|
? CupertinoColors.destructiveRed.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.error;
|
|
|
|
/// Resolve native text roles from the actual host, not Material's fallback
|
|
/// light theme when mounted under a dark CupertinoApp.
|
|
TextStyle settingsTextStyle(
|
|
BuildContext context, {
|
|
bool title = false,
|
|
bool secondary = false,
|
|
bool error = false,
|
|
}) {
|
|
if (usesCupertinoControls(context)) {
|
|
final text = CupertinoTheme.of(context).textTheme;
|
|
return (title ? text.navTitleTextStyle : text.textStyle).copyWith(
|
|
color: error
|
|
? settingsErrorColor(context)
|
|
: (secondary ? CupertinoColors.secondaryLabel : CupertinoColors.label)
|
|
.resolveFrom(context),
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
final base = (title
|
|
? theme.textTheme.titleMedium
|
|
: theme.textTheme.bodyMedium)!;
|
|
return base.copyWith(
|
|
color: error
|
|
? theme.colorScheme.error
|
|
: secondary
|
|
? theme.colorScheme.onSurfaceVariant
|
|
: base.color,
|
|
);
|
|
}
|