grant_permissions_widget.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'package:flutter/material.dart';
  2. import 'package:photo_manager/photo_manager.dart';
  3. import 'package:photos/services/sync_service.dart';
  4. import 'package:photos/ui/common_elements.dart';
  5. import 'package:photos/utils/toast_util.dart';
  6. class GrantPermissionsWidget extends StatelessWidget {
  7. @override
  8. Widget build(BuildContext context) {
  9. return Center(
  10. child: Column(
  11. mainAxisAlignment: MainAxisAlignment.center,
  12. crossAxisAlignment: CrossAxisAlignment.center,
  13. children: [
  14. Image.asset(
  15. "assets/gallery.png",
  16. height: 160,
  17. ),
  18. Padding(padding: EdgeInsets.all(24)),
  19. Text.rich(
  20. TextSpan(
  21. children: <TextSpan>[
  22. TextSpan(
  23. text: "ente",
  24. style: TextStyle(
  25. fontWeight: FontWeight.bold,
  26. fontFamily: 'Montserrat',
  27. fontSize: 16,
  28. ),
  29. ),
  30. TextSpan(
  31. text: " needs your permission",
  32. style: TextStyle(
  33. fontSize: 16,
  34. ),
  35. ),
  36. ],
  37. ),
  38. textAlign: TextAlign.center,
  39. ),
  40. Padding(padding: EdgeInsets.all(2)),
  41. Text(
  42. "to access your gallery",
  43. style: TextStyle(fontSize: 16),
  44. ),
  45. Padding(padding: const EdgeInsets.all(24)),
  46. Container(
  47. width: double.infinity,
  48. height: 64,
  49. padding: const EdgeInsets.fromLTRB(64, 0, 64, 0),
  50. child: button(
  51. "grant permission",
  52. fontSize: 16,
  53. onPressed: () async {
  54. final state = await PhotoManager.requestPermissionExtend();
  55. if (state == PermissionState.authorized ||
  56. state == PermissionState.limited) {
  57. await SyncService.instance.onPermissionGranted(state);
  58. } else if (state == PermissionState.denied) {
  59. AlertDialog alert = AlertDialog(
  60. title: Text("please grant permissions"),
  61. content: Text(
  62. "ente can encrypt and preserve files only if you grant access to them"),
  63. actions: [
  64. TextButton(
  65. child: Text(
  66. "ok",
  67. style: TextStyle(
  68. color: Theme.of(context).buttonColor,
  69. ),
  70. ),
  71. onPressed: () {
  72. Navigator.of(context, rootNavigator: true)
  73. .pop('dialog');
  74. PhotoManager.openSetting();
  75. },
  76. ),
  77. ],
  78. );
  79. showDialog(
  80. context: context,
  81. builder: (BuildContext context) {
  82. return alert;
  83. },
  84. barrierColor: Colors.black87,
  85. );
  86. }
  87. },
  88. ),
  89. ),
  90. Padding(padding: const EdgeInsets.all(50)),
  91. Text(
  92. "we value your privacy",
  93. style: TextStyle(
  94. color: Colors.white30,
  95. ),
  96. ),
  97. Padding(padding: const EdgeInsets.all(12)),
  98. Text(
  99. "all the files you choose to back up",
  100. style: TextStyle(
  101. color: Colors.white30,
  102. ),
  103. ),
  104. Padding(padding: const EdgeInsets.all(2)),
  105. Text(
  106. "will be end-to-end encrypted",
  107. style: TextStyle(
  108. color: Colors.white30,
  109. ),
  110. ),
  111. ],
  112. ),
  113. );
  114. }
  115. }