ente/lib/ui/grant_permissions_widget.dart

142 lines
4.7 KiB
Dart
Raw Normal View History

// @dart=2.9
2021-07-01 12:33:02 +00:00
import 'dart:io';
2021-03-12 08:40:36 +00:00
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:photos/services/sync_service.dart';
2021-05-09 18:44:05 +00:00
2021-05-29 17:01:59 +00:00
class GrantPermissionsWidget extends StatelessWidget {
const GrantPermissionsWidget({Key key}) : super(key: key);
2021-03-12 08:40:36 +00:00
@override
Widget build(BuildContext context) {
2022-07-03 09:49:33 +00:00
final isLightMode =
MediaQuery.of(context).platformBrightness == Brightness.light;
2022-03-27 04:42:26 +00:00
return Scaffold(
body: SingleChildScrollView(
2022-07-07 11:35:33 +00:00
child: Padding(
padding: const EdgeInsets.only(top: 20, bottom: 120),
child: Column(
children: [
const SizedBox(
height: 24,
),
2022-07-07 11:35:33 +00:00
Center(
child: Stack(
alignment: Alignment.center,
children: [
isLightMode
? Image.asset(
'assets/loading_photos_background.png',
color: Colors.white.withOpacity(0.4),
colorBlendMode: BlendMode.modulate,
)
: Image.asset(
'assets/loading_photos_background_dark.png',
2022-06-10 14:10:37 +00:00
),
2022-07-07 11:35:33 +00:00
Center(
child: Column(
children: [
const SizedBox(height: 42),
Image.asset(
"assets/gallery_locked.png",
height: 160,
),
],
),
),
2022-07-07 11:35:33 +00:00
],
),
2022-07-07 11:35:33 +00:00
),
const SizedBox(height: 36),
2022-07-07 11:35:33 +00:00
Padding(
padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
child: RichText(
text: TextSpan(
style: Theme.of(context)
.textTheme
.headline5
.copyWith(fontWeight: FontWeight.w700),
children: [
const TextSpan(text: 'ente '),
TextSpan(
text: "needs permission to ",
style: Theme.of(context)
.textTheme
.headline5
.copyWith(fontWeight: FontWeight.w400),
),
const TextSpan(text: 'preserve your photos'),
],
),
2022-06-11 08:23:52 +00:00
),
2022-07-07 11:35:33 +00:00
),
],
),
),
),
floatingActionButton: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Theme.of(context).backgroundColor,
spreadRadius: 190,
blurRadius: 30,
2022-07-04 06:02:17 +00:00
offset: const Offset(0, 170),
)
],
),
width: double.infinity,
2022-07-07 10:40:11 +00:00
padding: const EdgeInsets.only(
left: 20,
right: 20,
2022-07-07 10:40:11 +00:00
bottom: 16,
),
child: OutlinedButton(
2022-07-04 06:02:17 +00:00
child: const Text("Grant permission"),
onPressed: () async {
final state = await PhotoManager.requestPermissionExtend();
2022-07-03 09:49:33 +00:00
if (state == PermissionState.authorized ||
state == PermissionState.limited) {
await SyncService.instance.onPermissionGranted(state);
} else if (state == PermissionState.denied) {
2022-08-29 14:43:31 +00:00
final AlertDialog alert = AlertDialog(
2022-07-04 06:02:17 +00:00
title: const Text("Please grant permissions"),
content: const Text(
"ente can encrypt and preserve files only if you grant access to them",
),
actions: [
TextButton(
child: Text(
"OK",
style: Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 14,
fontWeight: FontWeight.w700,
),
),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop('dialog');
if (Platform.isIOS) {
PhotoManager.openSetting();
}
},
),
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
barrierColor: Colors.black12,
);
}
},
),
2021-03-12 08:40:36 +00:00
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
2021-03-12 08:40:36 +00:00
);
}
}