grant_permissions_widget.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:photo_manager/photo_manager.dart';
  4. import 'package:photos/services/sync_service.dart';
  5. import 'package:photos/ui/common_elements.dart';
  6. class GrantPermissionsWidget extends StatelessWidget {
  7. @override
  8. Widget build(BuildContext context) {
  9. return Center(
  10. child: SingleChildScrollView(
  11. child: Column(
  12. mainAxisAlignment: MainAxisAlignment.center,
  13. crossAxisAlignment: CrossAxisAlignment.center,
  14. children: [
  15. Image.asset(
  16. "assets/gallery.png",
  17. height: 160,
  18. ),
  19. Padding(padding: EdgeInsets.all(24)),
  20. Text.rich(
  21. TextSpan(
  22. children: <TextSpan>[
  23. TextSpan(
  24. text: "ente",
  25. style: TextStyle(
  26. fontWeight: FontWeight.bold,
  27. fontFamily: 'Montserrat',
  28. fontSize: 16,
  29. ),
  30. ),
  31. TextSpan(
  32. text: " needs your permission",
  33. style: TextStyle(
  34. fontSize: 16,
  35. ),
  36. ),
  37. ],
  38. ),
  39. textAlign: TextAlign.center,
  40. ),
  41. Padding(padding: EdgeInsets.all(2)),
  42. Text(
  43. "to access your gallery",
  44. style: TextStyle(fontSize: 16),
  45. ),
  46. Padding(padding: const EdgeInsets.all(24)),
  47. Container(
  48. width: double.infinity,
  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. if (Platform.isIOS) {
  75. PhotoManager.openSetting();
  76. }
  77. },
  78. ),
  79. ],
  80. );
  81. showDialog(
  82. context: context,
  83. builder: (BuildContext context) {
  84. return alert;
  85. },
  86. barrierColor: Colors.black87,
  87. );
  88. }
  89. },
  90. ),
  91. ),
  92. Padding(padding: const EdgeInsets.all(50)),
  93. Text(
  94. "we value your privacy",
  95. style: TextStyle(
  96. color: Colors.white30,
  97. ),
  98. ),
  99. Padding(padding: const EdgeInsets.all(12)),
  100. Text(
  101. "the files you choose to back up",
  102. style: TextStyle(
  103. color: Colors.white30,
  104. ),
  105. ),
  106. Padding(padding: const EdgeInsets.all(2)),
  107. Text(
  108. "will be end-to-end encrypted",
  109. style: TextStyle(
  110. color: Colors.white30,
  111. ),
  112. ),
  113. ],
  114. ),
  115. ),
  116. );
  117. }
  118. }