grant_permissions_widget.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. return Scaffold(
  12. body: SingleChildScrollView(
  13. physics: NeverScrollableScrollPhysics(),
  14. child: SizedBox(
  15. height: MediaQuery.of(context).size.height,
  16. child: Column(
  17. crossAxisAlignment: CrossAxisAlignment.start,
  18. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  19. children: [
  20. Column(
  21. children: [
  22. Center(
  23. child: Padding(
  24. padding: const EdgeInsets.fromLTRB(0, 140, 0, 50),
  25. child: Image.asset(
  26. "assets/gallery.png",
  27. height: 220,
  28. ),
  29. ),
  30. ),
  31. Padding(
  32. padding: const EdgeInsets.symmetric(horizontal: 40),
  33. child: RichText(
  34. text: TextSpan(
  35. style: Theme.of(context)
  36. .textTheme
  37. .headline5
  38. .copyWith(fontWeight: FontWeight.w700),
  39. children: [
  40. TextSpan(text: 'ente '),
  41. TextSpan(
  42. text: "needs permission to ",
  43. style: Theme.of(context)
  44. .textTheme
  45. .headline5
  46. .copyWith(fontWeight: FontWeight.w400)),
  47. TextSpan(text: 'preserve your photos')
  48. ])),
  49. ),
  50. ],
  51. ),
  52. Container(
  53. width: double.infinity,
  54. padding: EdgeInsets.only(
  55. left: 20, right: 20, bottom: Platform.isIOS ? 24 : 60),
  56. child: OutlinedButton(
  57. child: Text("Grant permission"),
  58. onPressed: () async {
  59. final state = await PhotoManager.requestPermissionExtend();
  60. if (state == PermissionState.authorized ||
  61. state == PermissionState.limited) {
  62. await SyncService.instance.onPermissionGranted(state);
  63. } else if (state == PermissionState.denied) {
  64. AlertDialog alert = AlertDialog(
  65. title: Text("Please grant permissions"),
  66. content: Text(
  67. "ente can encrypt and preserve files only if you grant access to them"),
  68. actions: [
  69. TextButton(
  70. child: Text(
  71. "OK",
  72. style: Theme.of(context)
  73. .textTheme
  74. .subtitle1
  75. .copyWith(
  76. fontSize: 14,
  77. fontWeight: FontWeight.w700),
  78. ),
  79. onPressed: () {
  80. Navigator.of(context, rootNavigator: true)
  81. .pop('dialog');
  82. if (Platform.isIOS) {
  83. PhotoManager.openSetting();
  84. }
  85. },
  86. ),
  87. ],
  88. );
  89. showDialog(
  90. context: context,
  91. builder: (BuildContext context) {
  92. return BackdropFilter(
  93. filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
  94. child: alert,
  95. );
  96. },
  97. barrierColor: Colors.black12,
  98. );
  99. }
  100. },
  101. ),
  102. ),
  103. ],
  104. ),
  105. ),
  106. ),
  107. );
  108. }
  109. }