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';
|
2023-04-06 08:51:23 +00:00
|
|
|
import "package:photos/generated/l10n.dart";
|
2021-03-12 08:40:36 +00:00
|
|
|
import 'package:photos/services/sync_service.dart';
|
2023-06-27 08:16:44 +00:00
|
|
|
import "package:styled_text/styled_text.dart";
|
2021-05-09 18:44:05 +00:00
|
|
|
|
2021-05-29 17:01:59 +00:00
|
|
|
class GrantPermissionsWidget extends StatelessWidget {
|
2022-12-28 04:43:30 +00:00
|
|
|
const GrantPermissionsWidget({Key? key}) : super(key: key);
|
2021-03-12 08:40:36 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-30 07:49:36 +00:00
|
|
|
final isLightMode = Theme.of(context).brightness == Brightness.light;
|
2022-03-27 04:42:26 +00:00
|
|
|
return Scaffold(
|
2022-06-01 07:20:42 +00:00
|
|
|
body: SingleChildScrollView(
|
2022-07-07 11:35:33 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20, bottom: 120),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-09-05 05:15:14 +00:00
|
|
|
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-06-01 07:20:42 +00:00
|
|
|
),
|
2022-07-07 11:35:33 +00:00
|
|
|
],
|
2022-06-13 15:13:29 +00:00
|
|
|
),
|
2022-07-07 11:35:33 +00:00
|
|
|
),
|
2022-09-05 05:15:14 +00:00
|
|
|
const SizedBox(height: 36),
|
2022-07-07 11:35:33 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
|
2023-06-27 08:16:44 +00:00
|
|
|
child: StyledText(
|
|
|
|
text: S.of(context).entePhotosPerm,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headlineSmall!
|
|
|
|
.copyWith(fontWeight: FontWeight.w700),
|
|
|
|
tags: {
|
|
|
|
'i': StyledTextTag(
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headlineSmall!
|
|
|
|
.copyWith(fontWeight: FontWeight.w400),
|
|
|
|
),
|
|
|
|
},
|
2022-06-11 08:23:52 +00:00
|
|
|
),
|
2022-07-07 11:35:33 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-06-13 15:13:29 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
floatingActionButton: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
2023-06-13 09:09:55 +00:00
|
|
|
color: Theme.of(context).colorScheme.background,
|
2022-06-29 07:57:55 +00:00
|
|
|
spreadRadius: 190,
|
|
|
|
blurRadius: 30,
|
2022-07-04 06:02:17 +00:00
|
|
|
offset: const Offset(0, 170),
|
2023-08-19 11:39:56 +00:00
|
|
|
),
|
2022-06-13 15:13:29 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
width: double.infinity,
|
2022-07-07 10:40:11 +00:00
|
|
|
padding: const EdgeInsets.only(
|
2022-06-13 15:13:29 +00:00
|
|
|
left: 20,
|
|
|
|
right: 20,
|
2022-07-07 10:40:11 +00:00
|
|
|
bottom: 16,
|
2022-06-13 15:13:29 +00:00
|
|
|
),
|
|
|
|
child: OutlinedButton(
|
2023-05-12 06:16:25 +00:00
|
|
|
key: const ValueKey("grantPermissionButton"),
|
2023-04-08 04:05:16 +00:00
|
|
|
child: Text(S.of(context).grantPermission),
|
2022-06-13 15:13:29 +00:00
|
|
|
onPressed: () async {
|
|
|
|
final state = await PhotoManager.requestPermissionExtend();
|
2022-07-03 09:49:33 +00:00
|
|
|
if (state == PermissionState.authorized ||
|
|
|
|
state == PermissionState.limited) {
|
2022-06-13 15:13:29 +00:00
|
|
|
await SyncService.instance.onPermissionGranted(state);
|
|
|
|
} else if (state == PermissionState.denied) {
|
2022-08-29 14:43:31 +00:00
|
|
|
final AlertDialog alert = AlertDialog(
|
2023-04-06 08:51:23 +00:00
|
|
|
title: Text(S.of(context).pleaseGrantPermissions),
|
|
|
|
content: Text(
|
|
|
|
S.of(context).enteCanEncryptAndPreserveFilesOnlyIfYouGrant,
|
2022-06-13 15:13:29 +00:00
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
2023-04-06 08:51:23 +00:00
|
|
|
S.of(context).ok,
|
2023-06-13 06:41:31 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(
|
2022-06-13 15:13:29 +00:00
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.w700,
|
2022-06-01 07:20:42 +00:00
|
|
|
),
|
2022-06-13 15:13:29 +00:00
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop('dialog');
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
PhotoManager.openSetting();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2022-06-01 07:20:42 +00:00
|
|
|
|
2022-06-13 15:13:29 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
barrierColor: Colors.black12,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2022-06-01 07:20:42 +00:00
|
|
|
),
|
2021-03-12 08:40:36 +00:00
|
|
|
),
|
2022-06-13 15:13:29 +00:00
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
2021-03-12 08:40:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|