grant_permissions_widget.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo_manager/photo_manager.dart';
  4. import "package:photos/generated/l10n.dart";
  5. import 'package:photos/services/sync_service.dart';
  6. import "package:styled_text/styled_text.dart";
  7. class GrantPermissionsWidget extends StatelessWidget {
  8. const GrantPermissionsWidget({Key? key}) : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. final isLightMode = Theme.of(context).brightness == Brightness.light;
  12. return Scaffold(
  13. body: SingleChildScrollView(
  14. child: Padding(
  15. padding: const EdgeInsets.only(top: 20, bottom: 120),
  16. child: Column(
  17. children: [
  18. const SizedBox(
  19. height: 24,
  20. ),
  21. Center(
  22. child: Stack(
  23. alignment: Alignment.center,
  24. children: [
  25. isLightMode
  26. ? Image.asset(
  27. 'assets/loading_photos_background.png',
  28. color: Colors.white.withOpacity(0.4),
  29. colorBlendMode: BlendMode.modulate,
  30. )
  31. : Image.asset(
  32. 'assets/loading_photos_background_dark.png',
  33. ),
  34. Center(
  35. child: Column(
  36. children: [
  37. const SizedBox(height: 42),
  38. Image.asset(
  39. "assets/gallery_locked.png",
  40. height: 160,
  41. ),
  42. ],
  43. ),
  44. ),
  45. ],
  46. ),
  47. ),
  48. const SizedBox(height: 36),
  49. Padding(
  50. padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
  51. child: StyledText(
  52. text: S.of(context).entePhotosPerm,
  53. style: Theme.of(context)
  54. .textTheme
  55. .headlineSmall!
  56. .copyWith(fontWeight: FontWeight.w700),
  57. tags: {
  58. 'i': StyledTextTag(
  59. style: Theme.of(context)
  60. .textTheme
  61. .headlineSmall!
  62. .copyWith(fontWeight: FontWeight.w400),
  63. ),
  64. },
  65. ),
  66. ),
  67. ],
  68. ),
  69. ),
  70. ),
  71. floatingActionButton: Container(
  72. decoration: BoxDecoration(
  73. boxShadow: [
  74. BoxShadow(
  75. color: Theme.of(context).colorScheme.background,
  76. spreadRadius: 190,
  77. blurRadius: 30,
  78. offset: const Offset(0, 170),
  79. ),
  80. ],
  81. ),
  82. width: double.infinity,
  83. padding: const EdgeInsets.only(
  84. left: 20,
  85. right: 20,
  86. bottom: 16,
  87. ),
  88. child: OutlinedButton(
  89. key: const ValueKey("grantPermissionButton"),
  90. child: Text(S.of(context).grantPermission),
  91. onPressed: () async {
  92. final state = await PhotoManager.requestPermissionExtend();
  93. if (state == PermissionState.authorized ||
  94. state == PermissionState.limited) {
  95. await SyncService.instance.onPermissionGranted(state);
  96. } else if (state == PermissionState.denied) {
  97. final AlertDialog alert = AlertDialog(
  98. title: Text(S.of(context).pleaseGrantPermissions),
  99. content: Text(
  100. S.of(context).enteCanEncryptAndPreserveFilesOnlyIfYouGrant,
  101. ),
  102. actions: [
  103. TextButton(
  104. child: Text(
  105. S.of(context).ok,
  106. style: Theme.of(context).textTheme.titleMedium!.copyWith(
  107. fontSize: 14,
  108. fontWeight: FontWeight.w700,
  109. ),
  110. ),
  111. onPressed: () {
  112. Navigator.of(context, rootNavigator: true).pop('dialog');
  113. if (Platform.isIOS) {
  114. PhotoManager.openSetting();
  115. }
  116. },
  117. ),
  118. ],
  119. );
  120. showDialog(
  121. context: context,
  122. builder: (BuildContext context) {
  123. return alert;
  124. },
  125. barrierColor: Colors.black12,
  126. );
  127. }
  128. },
  129. ),
  130. ),
  131. floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
  132. );
  133. }
  134. }