ente/lib/ui/grant_permissions_widget.dart

94 lines
3.3 KiB
Dart
Raw Normal View History

2021-07-01 12:33:02 +00:00
import 'dart:io';
2022-03-27 04:42:26 +00:00
import 'dart:ui';
2021-07-01 12:33:02 +00:00
2021-03-12 08:40:36 +00:00
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
2022-04-22 11:32:20 +00:00
// import 'package:photos/ente_theme_data.dart';
2021-03-12 08:40:36 +00:00
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 {
2021-03-12 08:40:36 +00:00
@override
Widget build(BuildContext context) {
2022-03-27 04:42:26 +00:00
return Scaffold(
2022-04-22 11:32:20 +00:00
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 50),
child: Image.asset(
"assets/gallery.png",
height: 250,
2021-05-12 15:23:22 +00:00
),
),
2022-03-27 04:42:26 +00:00
),
2022-04-22 11:32:20 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
'ente needs your permission to access gallery',
style: Theme.of(context)
.textTheme
.headline4
.copyWith(height: 1.4),
),
2022-03-27 04:42:26 +00:00
),
2022-04-22 11:32:20 +00:00
],
),
Container(
width: double.infinity,
padding: EdgeInsets.only(
left: 20, right: 20, bottom: Platform.isIOS ? 60 : 32),
child: OutlinedButton(
child: Text("Grant Permission"),
onPressed: () async {
final state = await PhotoManager.requestPermissionExtend();
if (state == PermissionState.authorized ||
state == PermissionState.limited) {
await SyncService.instance.onPermissionGranted(state);
} else if (state == PermissionState.denied) {
AlertDialog alert = AlertDialog(
title: Text("Please grant permissions"),
content: 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();
}
},
),
2022-04-22 11:32:20 +00:00
],
);
2022-04-22 11:32:20 +00:00
showDialog(
context: context,
builder: (BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: alert,
);
},
barrierColor: Colors.black12,
);
}
},
// padding: EdgeInsets.fromLTRB(12, 20, 12, 20),
),
),
],
2021-03-12 08:40:36 +00:00
),
);
}
}