ente/lib/ui/set_wallpaper_dialog.dart

92 lines
2.8 KiB
Dart
Raw Normal View History

2021-07-06 09:57:30 +00:00
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/models/file.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/file_util.dart';
import 'package:photos/utils/toast_util.dart';
2021-07-10 07:51:54 +00:00
import 'package:wallpaper_manager_flutter/wallpaper_manager_flutter.dart';
2021-07-06 09:57:30 +00:00
class SetWallpaperDialog extends StatefulWidget {
final File file;
const SetWallpaperDialog(this.file, {Key key}) : super(key: key);
@override
_SetWallpaperDialogState createState() => _SetWallpaperDialogState();
}
class _SetWallpaperDialogState extends State<SetWallpaperDialog> {
2021-07-10 07:51:54 +00:00
int _lockscreenValue = WallpaperManagerFlutter.HOME_SCREEN;
2021-07-06 09:57:30 +00:00
@override
Widget build(BuildContext context) {
final alert = AlertDialog(
title: Text("set wallpaper"),
content: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
RadioListTile(
title: const Text("homescreen"),
2021-07-10 07:51:54 +00:00
value: WallpaperManagerFlutter.HOME_SCREEN,
2021-07-06 09:57:30 +00:00
groupValue: _lockscreenValue,
onChanged: (v) {
setState(() {
_lockscreenValue = v;
});
},
),
RadioListTile(
title: const Text("lockscreen"),
2021-07-10 07:51:54 +00:00
value: WallpaperManagerFlutter.LOCK_SCREEN,
2021-07-06 09:57:30 +00:00
groupValue: _lockscreenValue,
onChanged: (v) {
setState(() {
_lockscreenValue = v;
});
},
),
RadioListTile(
title: const Text("both"),
2021-07-10 07:51:54 +00:00
value: WallpaperManagerFlutter.BOTH_SCREENS,
2021-07-06 09:57:30 +00:00
groupValue: _lockscreenValue,
onChanged: (v) {
setState(() {
_lockscreenValue = v;
});
},
),
],
),
),
actions: [
TextButton(
child: Text(
"ok",
style: TextStyle(
color: Colors.white,
),
),
onPressed: () async {
Navigator.of(context, rootNavigator: true).pop('dialog');
final dialog = createProgressDialog(context, "setting wallpaper");
await dialog.show();
try {
2021-07-10 07:51:54 +00:00
await WallpaperManagerFlutter().setwallpaperfromFile(
await getFile(widget.file), _lockscreenValue);
2021-07-06 09:57:30 +00:00
await dialog.hide();
showToast("wallpaper set successfully");
} catch (e, s) {
await dialog.hide();
Logger("SetWallpaperDialog").severe(e, s);
showToast("something went wrong");
return;
}
},
),
],
);
return alert;
}
}