Skip to content
Merged
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
4 changes: 2 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
applicationId = "com.example.the_wallpaper_company"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 23
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
Expand Down Expand Up @@ -60,4 +60,4 @@ dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")

// Other dependencies for your project...
}
}
82 changes: 82 additions & 0 deletions lib/core/providers/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ThemeProvider extends ChangeNotifier {
bool _isDarkMode = false;
static const String _themePreferenceKey = 'isDarkMode';

bool get isDarkMode => _isDarkMode;

ThemeProvider() {
_loadThemePreference();
}

void toggleTheme() {
_isDarkMode = !_isDarkMode;
_saveThemePreference();
notifyListeners();
}

void setDarkMode(bool value) {
_isDarkMode = value;
_saveThemePreference();
notifyListeners();
}

Future<void> _loadThemePreference() async {
try {
final prefs = await SharedPreferences.getInstance();
_isDarkMode = prefs.getBool(_themePreferenceKey) ?? false;
notifyListeners();
} catch (e) {
debugPrint('Error loading theme preference: $e');
}
}

Future<void> _saveThemePreference() async {
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_themePreferenceKey, _isDarkMode);
} catch (e) {
debugPrint('Error saving theme preference: $e');
}
}

ThemeData get lightTheme => ThemeData.light().copyWith(
primaryColor: Colors.pinkAccent,
scaffoldBackgroundColor: const Color(0xFFF5F5F5),
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
elevation: 0,
iconTheme: IconThemeData(color: Colors.black87),
titleTextStyle: TextStyle(
color: Colors.black87,
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.black87),
bodyMedium: TextStyle(color: Colors.black87),
),
);

ThemeData get darkTheme => ThemeData.dark().copyWith(
primaryColor: Colors.pinkAccent,
scaffoldBackgroundColor: Colors.black,
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
elevation: 0,
iconTheme: IconThemeData(color: Colors.white),
titleTextStyle: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.white),
bodyMedium: TextStyle(color: Colors.white),
),
);
}
110 changes: 64 additions & 46 deletions lib/features/home/presentation/screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:the_wallpaper_company/features/home/presentation/widgets/wallpap
import 'package:the_wallpaper_company/features/home/provider/wallpaper_provider.dart';
import 'package:the_wallpaper_company/firebase_message.dart';
import '../widgets/category_carousel.dart';
import '../widgets/search_bar_widget.dart';
import '../widgets/no_results_widget.dart';
import 'package:the_wallpaper_company/core/constants.dart';
import 'package:the_wallpaper_company/features/home/presentation/widgets/wallpaper_tile.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
Expand Down Expand Up @@ -121,60 +123,76 @@ class _HomeScreenState extends State<HomeScreen> {
sigmaX: 12,
sigmaY: 12,
),
child: CategoryCarousel(
categories: AppConstants.categories,
selectedCategory:
provider.selectedCategory,
onCategorySelected:
provider.selectCategory,
child: Column(
children: [
const SearchBarWidget(),
CategoryCarousel(
categories:
AppConstants.categories,
selectedCategory:
provider.selectedCategory,
onCategorySelected:
provider.selectCategory,
),
],
),
),
),
),
// expandedHeight: 72,
toolbarHeight: 150,
toolbarHeight: 220,
),
SliverPadding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 8,
),
sliver: SliverMasonryGrid.count(
crossAxisCount: 2,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
childCount:
visibleWallpapers.length +
(provider.isPaginating ? 1 : 0),
itemBuilder: (context, index) {
if (provider.isPaginating &&
index == visibleWallpapers.length) {
return const WallpaperShimmer();
}
final wallpaper =
visibleWallpapers[index];
return InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
WallpaperScreen(
wallpapers:
visibleWallpapers,
initialIndex: index,
visibleWallpapers.isEmpty &&
provider.searchQuery.isNotEmpty
? SliverFillRemaining(
child: NoResultsWidget(
searchQuery: provider.searchQuery,
onClearSearch: provider.clearSearch,
),
)
: SliverPadding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 8,
),
sliver: SliverMasonryGrid.count(
crossAxisCount: 2,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
childCount:
visibleWallpapers.length +
(provider.isPaginating ? 1 : 0),
itemBuilder: (context, index) {
if (provider.isPaginating &&
index ==
visibleWallpapers
.length) {
return const WallpaperShimmer();
}
final wallpaper =
visibleWallpapers[index];
return InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
WallpaperScreen(
wallpapers:
visibleWallpapers,
initialIndex: index,
),
),
),
);
},
child: WallpaperTile(
imageUrl: wallpaper.imageUrl,
title: wallpaper.title,
id: wallpaper.id,
);
},
child: WallpaperTile(
imageUrl: wallpaper.imageUrl,
title: wallpaper.title,
id: wallpaper.id,
),
);
},
),
);
},
),
),
),
],
),
),
Expand Down
68 changes: 68 additions & 0 deletions lib/features/home/presentation/widgets/no_results_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';

class NoResultsWidget extends StatelessWidget {
final String searchQuery;
final VoidCallback onClearSearch;

const NoResultsWidget({
super.key,
required this.searchQuery,
required this.onClearSearch,
});

@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.search_off,
size: 64,
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[600]
: Colors.grey[400],
),
const SizedBox(height: 16),
Text(
'No wallpapers found',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[400]
: Colors.grey[600],
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8),
Text(
'No results for "${searchQuery.trim()}"',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[500]
: Colors.grey[500],
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: onClearSearch,
icon: const Icon(Icons.clear),
label: const Text('Clear Search'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
),
),
],
),
),
);
}
}
Loading
Loading