nc-photos/lib/theme.dart

138 lines
4.6 KiB
Dart
Raw Normal View History

2021-04-10 06:28:12 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class AppTheme extends StatelessWidget {
const AppTheme({@required this.child});
@override
Widget build(BuildContext context) {
return Theme(
2021-07-16 09:55:04 +02:00
data: buildThemeData(context),
2021-04-10 06:28:12 +02:00
child: child,
);
}
2021-07-16 09:55:04 +02:00
static ThemeData buildThemeData(BuildContext context) {
final theme = Theme.of(context);
return theme.brightness == Brightness.light
? _buildLightThemeData(context, theme)
: _buildDarkThemeData(context, theme);
2021-04-10 06:28:12 +02:00
}
static AppBarTheme getContextualAppBarTheme(BuildContext context) {
final theme = Theme.of(context);
if (theme.brightness == Brightness.light) {
return theme.appBarTheme.copyWith(
brightness: Brightness.dark,
color: Colors.grey[800],
2021-04-17 10:59:16 +02:00
actionsIconTheme: theme.primaryIconTheme
.copyWith(color: Colors.white.withOpacity(.87)),
iconTheme: theme.primaryIconTheme
.copyWith(color: Colors.white.withOpacity(.87)),
textTheme: theme.primaryTextTheme
.apply(bodyColor: Colors.white.withOpacity(.87)),
2021-04-10 06:28:12 +02:00
);
} else {
return theme.appBarTheme.copyWith(
brightness: Brightness.dark,
color: Colors.grey[200],
2021-04-17 10:59:16 +02:00
actionsIconTheme:
theme.primaryIconTheme.copyWith(color: Colors.black87),
iconTheme: theme.primaryIconTheme.copyWith(color: Colors.black87),
textTheme: theme.primaryTextTheme.apply(bodyColor: Colors.black87),
2021-04-10 06:28:12 +02:00
);
}
}
static Color getSelectionOverlayColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? primarySwatchLight[100].withOpacity(0.7)
2021-04-17 10:59:16 +02:00
: primarySwatchDark[700].withOpacity(0.7);
2021-04-10 06:28:12 +02:00
}
static Color getSelectionCheckColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Colors.grey[800]
2021-04-17 10:59:16 +02:00
: Colors.grey[350];
2021-04-10 06:28:12 +02:00
}
static Color getOverscrollIndicatorColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Colors.grey[800]
: Colors.grey[200];
}
static Color getRootPickerContentBoxColor(BuildContext context) {
return Colors.blue[200];
}
2021-04-17 10:59:16 +02:00
static Color getPrimaryTextColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Colors.black87
: Colors.white.withOpacity(.87);
}
static Color getSecondaryTextColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Colors.black.withOpacity(.6)
: Colors.white60;
}
2021-04-17 11:04:46 +02:00
static Color getAppBarDarkModeSwitchColor(BuildContext context) {
return Colors.black87;
}
static Color getAppBarDarkModeSwitchTrackColor(BuildContext context) {
return Colors.white.withOpacity(.5);
}
2021-05-05 22:03:39 +02:00
static Color getListItemBackgroundColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.light
? Colors.black26
: Colors.white12;
}
2021-07-16 09:55:04 +02:00
static ThemeData _buildLightThemeData(BuildContext context, ThemeData theme) {
final appBarTheme = theme.appBarTheme.copyWith(
brightness: Brightness.dark,
color: theme.scaffoldBackgroundColor,
actionsIconTheme: theme.primaryIconTheme.copyWith(color: Colors.black87),
iconTheme: theme.primaryIconTheme.copyWith(color: Colors.black87),
textTheme: theme.primaryTextTheme.apply(bodyColor: Colors.black87),
);
return theme.copyWith(appBarTheme: appBarTheme);
}
static ThemeData _buildDarkThemeData(BuildContext context, ThemeData theme) {
final appBarTheme = theme.appBarTheme.copyWith(
brightness: Brightness.dark,
color: theme.scaffoldBackgroundColor,
actionsIconTheme:
theme.primaryIconTheme.copyWith(color: Colors.white.withOpacity(.87)),
iconTheme:
theme.primaryIconTheme.copyWith(color: Colors.white.withOpacity(.87)),
textTheme: theme.primaryTextTheme
.apply(bodyColor: Colors.white.withOpacity(.87)),
);
return theme.copyWith(appBarTheme: appBarTheme);
}
2021-04-10 06:28:12 +02:00
static const primarySwatchLight = Colors.blue;
static const primarySwatchDark = Colors.cyan;
static const widthLimitedContentMaxWidth = 550.0;
/// Make a TextButton look like a default FlatButton. See
/// https://flutter.dev/go/material-button-migration-guide
static final flatButtonStyle = TextButton.styleFrom(
primary: Colors.black87,
minimumSize: Size(88, 36),
padding: EdgeInsets.symmetric(horizontal: 16.0),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2.0)),
),
);
final Widget child;
}