Skip to content

Refactor themes #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MultiRepositoryProvider(
providers: [
RepositoryProvider<EmailListRepository>(
create: (context) => EmailListRepository(),
),
RepositoryProvider<NavigationService>(
create: (context) => NavigationService(),
),
RepositoryProvider<LaunchesRepository>(
create: (context) => diContainer.get<LaunchesRepository>(),
),
],
child: MultiBlocProvider(
providers: [
Expand All @@ -37,15 +31,14 @@ class MyApp extends StatelessWidget {
),
BlocProvider(
create: (context) => EmailListBloc(
messagesRepository:
RepositoryProvider.of<EmailListRepository>(context),
messagesRepository: diContainer.get<EmailListRepository>(),
)..add(
EmailListFetched(),
),
),
BlocProvider(
create: (context) => LaunchesBloc(
RepositoryProvider.of<LaunchesRepository>(context),
diContainer.get<LaunchesRepository>(),
)..add(
const LaunchesEvent.load(),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/bloc/theme/theme_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Map<AppTheme, ThemeData> getThemeData(MaterialTheme theme) {
AppTheme.system: theme.yellowLight(),
AppTheme.light: theme.yellowLight(),
AppTheme.lightGold: theme.orangeLight(),
AppTheme.lightMint: theme.yellowLightMediumContrast(),
AppTheme.lightMint: theme.brownLight(),
AppTheme.dark: theme.yellowDark(),
AppTheme.darkGold: theme.orangeDark(),
AppTheme.darkMint: theme.yellowDarkMediumContrast(),
AppTheme.experimental: theme.yellowDarkMediumContrast(),
AppTheme.darkMint: theme.brownDark(),
AppTheme.experimental: theme.yellowDark(),
};

return themeData;
Expand Down
10 changes: 7 additions & 3 deletions lib/di/di_initializer.config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'package:flutter_bloc_app_template/di/di_data_module.dart' as _i513;
import 'package:flutter_bloc_app_template/di/di_network_module.dart' as _i52;
import 'package:flutter_bloc_app_template/di/di_repository_module.dart'
as _i381;
import 'package:flutter_bloc_app_template/repository/email_list_repository.dart'
as _i678;
import 'package:flutter_bloc_app_template/repository/launches_repository.dart'
as _i11;
import 'package:flutter_bloc_app_template/repository/theme_repository.dart'
Expand All @@ -42,10 +44,12 @@ extension GetItInjectableX on _i174.GetIt {
);
final networkModule = _$NetworkModule();
final dIAppModule = _$DIAppModule();
final dIDataModule = _$DIDataModule();
final repositoryModule = _$RepositoryModule();
final dIDataModule = _$DIDataModule();
gh.factory<_i361.Dio>(() => networkModule.provideDio());
gh.factory<_i993.Talker>(() => dIAppModule.provideLogger());
gh.factory<_i678.EmailListRepository>(
() => repositoryModule.provideEmailListRepository());
gh.lazySingleton<_i409.GlobalKey<_i409.NavigatorState>>(
() => dIAppModule.key);
gh.lazySingleton<_i750.ThemeStorage>(() => dIDataModule.themeStorage);
Expand All @@ -65,6 +69,6 @@ class _$NetworkModule extends _i52.NetworkModule {}

class _$DIAppModule extends _i367.DIAppModule {}

class _$DIDataModule extends _i513.DIDataModule {}

class _$RepositoryModule extends _i381.RepositoryModule {}

class _$DIDataModule extends _i513.DIDataModule {}
4 changes: 4 additions & 0 deletions lib/di/di_repository_module.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_bloc_app_template/data/network/data_source/launches_network_data_source.dart';
import 'package:flutter_bloc_app_template/data/theme_storage.dart';
import 'package:flutter_bloc_app_template/repository/email_list_repository.dart';
import 'package:flutter_bloc_app_template/repository/launches_repository.dart';
import 'package:flutter_bloc_app_template/repository/theme_repository.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -10,6 +11,9 @@ abstract class RepositoryModule {
ThemeRepository provideAccidentsRepository(ThemeStorage themeStorage) =>
ThemeRepositoryImpl(themeStorage);

@factoryMethod
EmailListRepository provideEmailListRepository() => EmailListRepositoryImpl();

@factoryMethod
LaunchesRepository provideLaunchesRepository(LaunchesDataSource dataSource) =>
LaunchesRepositoryImpl(dataSource);
Expand Down
10 changes: 10 additions & 0 deletions lib/features/settings/theme_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

class ThemeItem extends StatelessWidget {
const ThemeItem({super.key});

@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
Comment on lines +3 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

ThemeItem widget is incomplete and needs implementation details

The current implementation uses a Placeholder widget, which is only meant for development and not for production use. For a proper theme item widget in a settings screen, you should:

  1. Include properties to represent theme data (name, colors, etc.)
  2. Implement a visual preview of the theme
  3. Add selection mechanism (typically with a radio button or highlight)
  4. Connect to the theme system for actual theme switching

Consider implementing a more complete version:

 class ThemeItem extends StatelessWidget {
-  const ThemeItem({super.key});
+  const ThemeItem({
+    super.key,
+    required this.themeName,
+    required this.isSelected,
+    required this.onSelect,
+    required this.themeColor,
+  });
+
+  final String themeName;
+  final bool isSelected;
+  final VoidCallback onSelect;
+  final Color themeColor;

   @override
   Widget build(BuildContext context) {
-    return const Placeholder();
+    return InkWell(
+      onTap: onSelect,
+      child: Container(
+        padding: const EdgeInsets.all(16),
+        decoration: BoxDecoration(
+          border: Border.all(
+            color: isSelected ? themeColor : Colors.grey.shade300,
+            width: isSelected ? 2 : 1,
+          ),
+          borderRadius: BorderRadius.circular(8),
+        ),
+        child: Row(
+          children: [
+            Container(
+              width: 24,
+              height: 24,
+              decoration: BoxDecoration(
+                color: themeColor,
+                shape: BoxShape.circle,
+              ),
+            ),
+            const SizedBox(width: 16),
+            Text(themeName),
+            const Spacer(),
+            if (isSelected)
+              Icon(Icons.check_circle, color: themeColor),
+          ],
+        ),
+      ),
+    );
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class ThemeItem extends StatelessWidget {
const ThemeItem({super.key});
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
import 'package:flutter/material.dart';
class ThemeItem extends StatelessWidget {
const ThemeItem({
super.key,
required this.themeName,
required this.isSelected,
required this.onSelect,
required this.themeColor,
});
final String themeName;
final bool isSelected;
final VoidCallback onSelect;
final Color themeColor;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onSelect,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(
color: isSelected ? themeColor : Colors.grey.shade300,
width: isSelected ? 2 : 1,
),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: themeColor,
shape: BoxShape.circle,
),
),
const SizedBox(width: 16),
Text(themeName),
const Spacer(),
if (isSelected) Icon(Icons.check_circle, color: themeColor),
],
),
),
);
}
}

7 changes: 6 additions & 1 deletion lib/repository/email_list_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import 'package:flutter_bloc_app_template/models/email.dart';

const _delay = Duration(milliseconds: 3000);

class EmailListRepository {
abstract class EmailListRepository {
Future<List<Email>> loadData();
}

class EmailListRepositoryImpl implements EmailListRepository {
@override
Future<List<Email>> loadData() {
emailList.sort((a, b) => b.date.compareTo(a.date));

Expand Down
Loading