grant_permissions_widget.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. class GrantPermissionsWidget extends StatelessWidget {
  7. const GrantPermissionsWidget({Key? key}) : super(key: key);
  8. @override
  9. Widget build(BuildContext context) {
  10. final isLightMode =
  11. MediaQuery.of(context).platformBrightness == 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: RichText(
  52. text: TextSpan(
  53. style: Theme.of(context)
  54. .textTheme
  55. .headline5!
  56. .copyWith(fontWeight: FontWeight.w700),
  57. children: [
  58. const TextSpan(text: 'ente '),
  59. TextSpan(
  60. text: "needs permission to ",
  61. style: Theme.of(context)
  62. .textTheme
  63. .headline5!
  64. .copyWith(fontWeight: FontWeight.w400),
  65. ),
  66. const TextSpan(text: 'preserve your photos'),
  67. ],
  68. ),
  69. ),
  70. ),
  71. ],
  72. ),
  73. ),
  74. ),
  75. floatingActionButton: Container(
  76. decoration: BoxDecoration(
  77. boxShadow: [
  78. BoxShadow(
  79. color: Theme.of(context).backgroundColor,
  80. spreadRadius: 190,
  81. blurRadius: 30,
  82. offset: const Offset(0, 170),
  83. )
  84. ],
  85. ),
  86. width: double.infinity,
  87. padding: const EdgeInsets.only(
  88. left: 20,
  89. right: 20,
  90. bottom: 16,
  91. ),
  92. child: OutlinedButton(
  93. child: Text(S.of(context).grantPermission),
  94. onPressed: () async {
  95. final state = await PhotoManager.requestPermissionExtend();
  96. if (state == PermissionState.authorized ||
  97. state == PermissionState.limited) {
  98. await SyncService.instance.onPermissionGranted(state);
  99. } else if (state == PermissionState.denied) {
  100. final AlertDialog alert = AlertDialog(
  101. title: Text(S.of(context).pleaseGrantPermissions),
  102. content: Text(
  103. S.of(context).enteCanEncryptAndPreserveFilesOnlyIfYouGrant,
  104. ),
  105. actions: [
  106. TextButton(
  107. child: Text(
  108. S.of(context).ok,
  109. style: Theme.of(context).textTheme.subtitle1!.copyWith(
  110. fontSize: 14,
  111. fontWeight: FontWeight.w700,
  112. ),
  113. ),
  114. onPressed: () {
  115. Navigator.of(context, rootNavigator: true).pop('dialog');
  116. if (Platform.isIOS) {
  117. PhotoManager.openSetting();
  118. }
  119. },
  120. ),
  121. ],
  122. );
  123. showDialog(
  124. context: context,
  125. builder: (BuildContext context) {
  126. return alert;
  127. },
  128. barrierColor: Colors.black12,
  129. );
  130. }
  131. },
  132. ),
  133. ),
  134. floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
  135. );
  136. }
  137. }