grant_permissions_widget.dart 5.1 KB

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