grant_permissions_widget.dart 3.3 KB

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