grant_permissions_widget.dart 4.7 KB

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