grant_permissions_widget.dart 4.6 KB

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