wallpapers_kit 0.2.1
wallpapers_kit: ^0.2.1 copied to clipboard
A Flutter wallpaper gallery toolkit: grid, category strip, full-screen viewer, favorites, set-as-wallpaper and download — themed to auto-match your app's light/dark mode.
import 'package:flutter/material.dart';
import 'package:wallpapers_kit/wallpapers_kit.dart';
void main() => runApp(const ExampleApp());
/// Sample catalog. In a real app this would come from your backend, a CMS,
/// or Firebase Remote Config — wallpapers_kit doesn't care where the list
/// comes from, it only needs a `List<Wallpaper>`.
final Map<String, List<Wallpaper>> _sampleCatalog = {
'Nature': List.generate(
8,
(i) => Wallpaper(
id: 'nature_$i',
url: 'https://picsum.photos/seed/nature$i/1080/1920',
thumbnailUrl: 'https://picsum.photos/seed/nature$i/400/640',
category: 'Nature',
),
),
'Abstract': List.generate(
8,
(i) => Wallpaper(
id: 'abstract_$i',
url: 'https://picsum.photos/seed/abstract$i/1080/1920',
thumbnailUrl: 'https://picsum.photos/seed/abstract$i/400/640',
category: 'Abstract',
),
),
'Minimal': List.generate(
8,
(i) => Wallpaper(
id: 'minimal_$i',
url: 'https://picsum.photos/seed/minimal$i/1080/1920',
thumbnailUrl: 'https://picsum.photos/seed/minimal$i/400/640',
category: 'Minimal',
),
),
};
final _favoritesStore = SharedPreferencesFavoritesStore();
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
ThemeMode _themeMode = ThemeMode.system;
void _toggleTheme() {
setState(() {
_themeMode = switch (_themeMode) {
ThemeMode.light => ThemeMode.dark,
ThemeMode.dark => ThemeMode.light,
ThemeMode.system => ThemeMode.light,
};
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'wallpapers_kit example',
// Two full ThemeData objects, one light and one dark. Every
// wallpapers_kit widget reads its colors from whichever of these is
// active via Theme.of(context) — flipping themeMode below is all it
// takes for the grid/viewer/favorites screens to follow along.
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal),
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.teal,
brightness: Brightness.dark,
),
),
themeMode: _themeMode,
home: HomeScreen(onToggleTheme: _toggleTheme, themeMode: _themeMode),
);
}
}
class HomeScreen extends StatelessWidget {
final VoidCallback onToggleTheme;
final ThemeMode themeMode;
const HomeScreen({
super.key,
required this.onToggleTheme,
required this.themeMode,
});
/// Stand-in for a rewarded-ad gate: wallpapers_kit ships no ad code at
/// all, so wiring one up (AdMob, or anything else) is entirely up to the
/// host app via this callback. Returning `true` lets the action proceed
/// immediately; a real implementation would await an ad finishing here.
Future<bool> _adGate(BuildContext context, String actionLabel) async {
return await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Ad goes here'),
content: Text(
'Your app would show a rewarded ad before "$actionLabel". '
'wallpapers_kit never shows ads itself — wire that up here.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Continue'),
),
],
),
) ??
false;
}
@override
Widget build(BuildContext context) {
final allWallpapers = _sampleCatalog.values.expand((w) => w).toList();
final categories = _sampleCatalog.entries
.map(
(e) => WallpaperCategory(
title: e.key,
thumbnailUrl: e.value.first.gridUrl,
),
)
.toList();
return Scaffold(
appBar: AppBar(
title: const Text('wallpapers_kit'),
actions: [
IconButton(
tooltip: 'Favorites',
icon: const Icon(Icons.favorite_border),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => Scaffold(
appBar: AppBar(title: const Text('Favorites')),
body: WallpaperFavoritesView(
allWallpapers: allWallpapers,
favoritesStore: _favoritesStore,
),
),
),
),
),
IconButton(
tooltip: 'Toggle light/dark theme',
icon: Icon(
themeMode == ThemeMode.dark ? Icons.dark_mode : Icons.light_mode,
),
onPressed: onToggleTheme,
),
],
),
body: WallpaperGridView(
wallpapers: allWallpapers,
favoritesStore: _favoritesStore,
onBeforeDownload: () => _adGate(context, 'download'),
onBeforeSetWallpaper: () => _adGate(context, 'set wallpaper'),
header: Padding(
padding: const EdgeInsets.only(bottom: 8),
child: WallpaperCategoryStrip(
categories: categories,
onCategoryTap: (category) {
final wallpapers = _sampleCatalog[category.title] ?? const [];
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => Scaffold(
appBar: AppBar(title: Text(category.title)),
body: WallpaperGridView(
wallpapers: wallpapers,
favoritesStore: _favoritesStore,
onBeforeDownload: () => _adGate(context, 'download'),
onBeforeSetWallpaper: () =>
_adGate(context, 'set wallpaper'),
),
),
),
);
},
),
),
),
);
}
}