first
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
/// Material 3 light and dark themes, including typography and component styles.
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Builds the [ThemeData] used by [MaterialApp] for light and dark mode.
|
||||
///
|
||||
/// Colors are generated from a single seed so both schemes stay consistent
|
||||
/// with Material 3 tonal palettes.
|
||||
abstract final class AppTheme {
|
||||
static const Color seed = Color(0xFF0F766E);
|
||||
|
||||
static ThemeData light() => _build(Brightness.light);
|
||||
|
||||
static ThemeData dark() => _build(Brightness.dark);
|
||||
|
||||
static ThemeData _build(Brightness brightness) {
|
||||
final colorScheme = ColorScheme.fromSeed(
|
||||
seedColor: seed,
|
||||
brightness: brightness,
|
||||
);
|
||||
|
||||
final isDark = brightness == Brightness.dark;
|
||||
final textTheme = _textTheme(colorScheme);
|
||||
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: colorScheme,
|
||||
textTheme: textTheme,
|
||||
scaffoldBackgroundColor: colorScheme.surface,
|
||||
appBarTheme: AppBarTheme(
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 1,
|
||||
backgroundColor: colorScheme.surface,
|
||||
foregroundColor: colorScheme.onSurface,
|
||||
titleTextStyle: textTheme.titleLarge,
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
elevation: 0,
|
||||
color: colorScheme.surfaceContainerLow,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
margin: EdgeInsets.zero,
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
elevation: 0,
|
||||
height: 72,
|
||||
backgroundColor: colorScheme.surfaceContainer,
|
||||
indicatorColor: colorScheme.secondaryContainer,
|
||||
labelTextStyle: WidgetStateProperty.resolveWith((states) {
|
||||
final selected = states.contains(WidgetState.selected);
|
||||
return textTheme.labelMedium?.copyWith(
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
||||
);
|
||||
}),
|
||||
),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
filled: true,
|
||||
fillColor: colorScheme.surfaceContainerHighest.withValues(alpha: 0.6),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: colorScheme.outlineVariant),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: colorScheme.primary, width: 2),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
style: FilledButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
textStyle: textTheme.labelLarge,
|
||||
),
|
||||
),
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
backgroundColor: colorScheme.primary,
|
||||
foregroundColor: colorScheme.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
dividerTheme: DividerThemeData(
|
||||
color: colorScheme.outlineVariant,
|
||||
space: 1,
|
||||
),
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
listTileTheme: ListTileThemeData(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
iconColor: colorScheme.primary,
|
||||
),
|
||||
shadowColor: isDark ? Colors.black : const Color(0x1A0F172A),
|
||||
);
|
||||
}
|
||||
|
||||
/// Slightly tighter, more editorial type scale than the Material defaults.
|
||||
static TextTheme _textTheme(ColorScheme colors) {
|
||||
const family = 'Roboto';
|
||||
return TextTheme(
|
||||
displaySmall: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -0.5,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
headlineMedium: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: -0.3,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
titleLarge: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
titleMedium: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
bodyLarge: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 16,
|
||||
height: 1.45,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 14,
|
||||
height: 1.4,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
labelLarge: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.1,
|
||||
color: colors.onPrimary,
|
||||
),
|
||||
labelMedium: TextStyle(
|
||||
fontFamily: family,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
letterSpacing: 0.4,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/// Shared string keys, timings, and layout breakpoints used across the app.
|
||||
library;
|
||||
|
||||
/// Human-readable name shown in the splash screen, app bars, and About tile.
|
||||
const String kAppName = 'MyApp';
|
||||
|
||||
/// Package / Android application id.
|
||||
const String kPackageName = 'com.example.myapp';
|
||||
|
||||
/// How long the splash screen stays visible before navigating to the shell.
|
||||
const Duration kSplashDuration = Duration(seconds: 2);
|
||||
|
||||
/// SharedPreferences keys.
|
||||
abstract final class StorageKeys {
|
||||
static const themeMode = 'theme_mode';
|
||||
static const useRemoteData = 'use_remote_data';
|
||||
}
|
||||
|
||||
/// Named routes registered on [MaterialApp].
|
||||
abstract final class AppRoutes {
|
||||
static const splash = '/';
|
||||
static const shell = '/shell';
|
||||
static const itemDetail = '/item';
|
||||
static const addItem = '/add-item';
|
||||
}
|
||||
|
||||
/// Width thresholds used to adapt padding and card density.
|
||||
abstract final class Breakpoints {
|
||||
static const compact = 600.0;
|
||||
static const medium = 840.0;
|
||||
}
|
||||
|
||||
/// Maximum content width on tablets / large phones so lists stay readable.
|
||||
const double kMaxContentWidth = 720.0;
|
||||
@@ -0,0 +1,59 @@
|
||||
/// Small pure helpers for layout, formatting, and user-facing strings.
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
|
||||
/// Horizontal padding that grows a little on wider screens.
|
||||
double pagePadding(double width) {
|
||||
if (width >= Breakpoints.medium) return 32;
|
||||
if (width >= Breakpoints.compact) return 24;
|
||||
return 16;
|
||||
}
|
||||
|
||||
/// Formats [date] as `MMM d, y` without pulling in `intl`.
|
||||
String formatDate(DateTime date) {
|
||||
const months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
return '${months[date.month - 1]} ${date.day}, ${date.year}';
|
||||
}
|
||||
|
||||
/// Converts a stored theme key into a [ThemeMode].
|
||||
ThemeMode themeModeFromName(String name) {
|
||||
return switch (name) {
|
||||
'light' => ThemeMode.light,
|
||||
'dark' => ThemeMode.dark,
|
||||
_ => ThemeMode.system,
|
||||
};
|
||||
}
|
||||
|
||||
/// Inverse of [themeModeFromName] for persistence.
|
||||
String nameFromThemeMode(ThemeMode mode) {
|
||||
return switch (mode) {
|
||||
ThemeMode.light => 'light',
|
||||
ThemeMode.dark => 'dark',
|
||||
ThemeMode.system => 'system',
|
||||
};
|
||||
}
|
||||
|
||||
/// Title-cases a [ThemeMode] for settings labels.
|
||||
String labelForThemeMode(ThemeMode mode) {
|
||||
return switch (mode) {
|
||||
ThemeMode.light => 'Light',
|
||||
ThemeMode.dark => 'Dark',
|
||||
ThemeMode.system => 'System',
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user