grant_permissions_widget.dart 4.7 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: Column(
  14. crossAxisAlignment: CrossAxisAlignment.start,
  15. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  16. children: [
  17. Column(
  18. children: [
  19. Center(
  20. child: Padding(
  21. padding: const EdgeInsets.fromLTRB(0, 100, 0, 50),
  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. Center(
  34. child: Image.asset(
  35. "assets/gallery_locked.png",
  36. height: 160,
  37. ),
  38. ),
  39. ],
  40. ),
  41. ),
  42. ),
  43. Padding(
  44. padding: const EdgeInsets.symmetric(horizontal: 40),
  45. child: RichText(
  46. text: TextSpan(
  47. style: Theme.of(context)
  48. .textTheme
  49. .headline5
  50. .copyWith(fontWeight: FontWeight.w700),
  51. children: [
  52. TextSpan(text: 'ente '),
  53. TextSpan(
  54. text: "needs permission to ",
  55. style: Theme.of(context)
  56. .textTheme
  57. .headline5
  58. .copyWith(fontWeight: FontWeight.w400),
  59. ),
  60. TextSpan(text: 'preserve your photos'),
  61. ],
  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: 200,
  76. blurRadius: 100,
  77. offset: Offset(0, 160),
  78. )
  79. ],
  80. ),
  81. width: double.infinity,
  82. padding: EdgeInsets.only(
  83. left: 20,
  84. right: 20,
  85. bottom: Platform.isIOS ? 40 : 16,
  86. ),
  87. child: OutlinedButton(
  88. child: 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. AlertDialog alert = AlertDialog(
  96. title: Text("Please grant permissions"),
  97. content: 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. }