Skip to content

Commit

Permalink
feat: use material 3 by default and fix deprecated errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro committed Nov 19, 2023
1 parent 3e520c2 commit 926ec5a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/advanced_theme/cubit/advanced_theme_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class AdvancedThemeState extends Equatable {
final bool isDark;
final bool useMaterial3;

const AdvancedThemeState({this.isDark = false, this.useMaterial3 = false});
const AdvancedThemeState({
this.isDark = false,
this.useMaterial3 = true,
});

@override
List<Object> get props => [isDark, useMaterial3];
Expand Down
15 changes: 13 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class _MaterialApp extends StatefulWidget {
}

class _MaterialAppState extends State<_MaterialApp> {
final _seedColor = Colors.blue;

@override
void initState() {
super.initState();
Expand All @@ -225,8 +227,17 @@ class _MaterialAppState extends State<_MaterialApp> {
builder: (context, state) {
return MaterialApp(
title: 'Appainter',
theme: ThemeData(),
darkTheme: ThemeData.dark(),
theme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(
seedColor: _seedColor,
),
),
darkTheme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(
seedColor: _seedColor,
brightness: Brightness.dark,
),
),
themeMode: state.themeMode,
home: state.status == HomeStatus.success
? const HomePage()
Expand Down
9 changes: 6 additions & 3 deletions lib/basic_theme/cubit/basic_theme_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BasicThemeState extends Equatable {
Color? seedColor,
ColorScheme? colorScheme,
this.isDark = false,
this.useMaterial3 = false,
this.useMaterial3 = true,
}) : seedColor = seedColor ?? defaultSeedColor,
colorScheme = colorScheme ?? _colorSchemeLight;

Expand Down Expand Up @@ -96,9 +96,12 @@ class BasicThemeState extends Equatable {

ThemeData get theme {
return ThemeData.localize(
ThemeData.from(colorScheme: colorScheme),
ThemeData.from(
colorScheme: colorScheme,
useMaterial3: useMaterial3,
),
Typography.englishLike2018,
).copyWith(useMaterial3: useMaterial3);
);
}

Brightness get brightness => isDark ? Brightness.dark : Brightness.light;
Expand Down
2 changes: 1 addition & 1 deletion lib/home/views/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HomePage extends StatefulWidget {
}

class HomePageState extends State<HomePage> {
static const _sdkVersion = '3.13.0+';
static const _sdkVersion = '3.16.0+';
static final _backgroundColorDark = Colors.grey[900]!;
static final _backgroundColorLight = Colors.grey[200]!;

Expand Down
2 changes: 1 addition & 1 deletion lib/home/widgets/material3_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Material3Switch extends StatelessWidget {
return Row(
children: [
Text(
'Material 3 (beta)',
'Material 3',
style: Theme.of(context).textTheme.titleMedium,
),
const _Switch(),
Expand Down
1 change: 1 addition & 0 deletions lib/theme_preview/views/theme_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ThemePreview extends StatelessWidget {
),
),
drawer: _Drawer(),
// ignore: prefer_const_constructors
body: TabBarView(
children: _pages,
),
Expand Down
3 changes: 1 addition & 2 deletions test/color_theme/color_theme_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@ void main() {
});

testWidgets('change color', (tester) async {
final opaqueColor = color.withOpacity(0.12);
await pumpApp(tester);
await tester.verifyColorPicker(
key,
opaqueColor,
color,
colorThemeCubit.dividerColorChanged,
);
});
Expand Down

0 comments on commit 926ec5a

Please sign in to comment.