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