grant_permissions_widget.dart 4.7 KB

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