wallx_setter 1.0.1
wallx_setter: ^1.0.1 copied to clipboard
A Flutter plugin to set wallpapers on Android devices. Simple, fast, and reliable way to change device wallpaper programmatically.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:wallx_setter/wallx_setter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Wallpaper Setter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _wallxSetterPlugin = WallxSetter();
bool _isLoading = false;
String _statusMessage = 'Wallpaper o\'rnatish uchun tugmani bosing';
// Wallpaper o'rnatish funksiyasi
Future<void> _setWallpaper() async {
setState(() {
_isLoading = true;
_statusMessage = 'O\'rnatilmoqda...';
});
try {
// Bu yerda haqiqiy rasm yo'lini kiriting
// Misol: /storage/emulated/0/Download/rasm.jpg
String imagePath = '/storage/emulated/0/Download/test.jpg';
bool? result = await _wallxSetterPlugin.setWallpaper(imagePath);
setState(() {
_isLoading = false;
if (result == true) {
_statusMessage = '✓ Wallpaper muvaffaqiyatli o\'rnatildi!';
} else {
_statusMessage = '✗ Xatolik: Rasm topilmadi yoki o\'rnatilmadi';
}
});
// SnackBar ko'rsatish
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
result == true ? 'Wallpaper o\'rnatildi!' : 'Xatolik yuz berdi!',
),
backgroundColor: result == true ? Colors.green : Colors.red,
),
);
}
} catch (e) {
setState(() {
_isLoading = false;
_statusMessage = '✗ Xatolik: $e';
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Wallpaper Setter'),
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Icon
Icon(
Icons.wallpaper,
size: 120,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 40),
// Status xabari
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(12),
),
child: Text(
_statusMessage,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
const SizedBox(height: 40),
// Tugma
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton.icon(
onPressed: _isLoading ? null : _setWallpaper,
icon: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor:
AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: const Icon(Icons.phone_android),
label: Text(
_isLoading ? 'O\'rnatilmoqda...' : 'Wallpaper O\'rnatish',
style: const TextStyle(fontSize: 18),
),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(height: 20),
// Ko'rsatma
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.blue.shade200),
),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'💡 Ko\'rsatma:',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
SizedBox(height: 8),
Text(
'1. Rasm faylini telefonga yuklang\n'
'2. Kodda rasm yo\'lini kiriting\n'
'3. Tugmani bosing\n'
'4. Wallpaper o\'rnatiladi!',
style: TextStyle(fontSize: 14),
),
],
),
),
],
),
),
),
);
}
}