loading_photos_widget.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:lottie/lottie.dart';
  4. import 'package:photos/core/event_bus.dart';
  5. import 'package:photos/ente_theme_data.dart';
  6. import 'package:photos/events/sync_status_update_event.dart';
  7. import 'package:photos/services/local_sync_service.dart';
  8. import 'package:photos/ui/backup_folder_selection_page.dart';
  9. import 'package:photos/ui/common/bottomShadow.dart';
  10. import 'package:photos/utils/navigation_util.dart';
  11. class LoadingPhotosWidget extends StatefulWidget {
  12. const LoadingPhotosWidget({Key key}) : super(key: key);
  13. @override
  14. State<LoadingPhotosWidget> createState() => _LoadingPhotosWidgetState();
  15. }
  16. class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
  17. StreamSubscription<SyncStatusUpdate> _firstImportEvent;
  18. int _currentPage = 0;
  19. final PageController _pageController = PageController(
  20. initialPage: 0,
  21. );
  22. final List<String> _messages = [
  23. "web.ente.io has a slick uploader",
  24. "We have preserved over 3 million memories so far",
  25. "All our apps are open source",
  26. "Our encryption protocols have been reviewed by engineers at Google, Apple, Amazon, and Facebook",
  27. "You can share links to your albums with your loved ones",
  28. "Our mobile apps run in the background to encrypt and backup new photos you take",
  29. "We use Xchacha20Poly1305 to safely encrypt your data",
  30. "One of our data centers is in an underground fall out shelter in Paris",
  31. ];
  32. @override
  33. void initState() {
  34. super.initState();
  35. _firstImportEvent =
  36. Bus.instance.on<SyncStatusUpdate>().listen((event) async {
  37. if (mounted && event.status == SyncStatus.completedFirstGalleryImport) {
  38. if (LocalSyncService.instance.hasGrantedLimitedPermissions()) {
  39. // Do nothing, let HomeWidget refresh
  40. } else {
  41. routeToPage(
  42. context,
  43. BackupFolderSelectionPage(
  44. isOnboarding: true,
  45. buttonText: "Start backup",
  46. ),
  47. );
  48. }
  49. }
  50. });
  51. Timer.periodic(Duration(seconds: 5), (Timer timer) {
  52. if (!mounted) {
  53. return;
  54. }
  55. if (_currentPage < _messages.length - 1) {
  56. _currentPage++;
  57. } else {
  58. _currentPage = 0;
  59. }
  60. _pageController.animateToPage(
  61. _currentPage,
  62. duration: Duration(milliseconds: 300),
  63. curve: Curves.easeIn,
  64. );
  65. });
  66. }
  67. @override
  68. void dispose() {
  69. _firstImportEvent.cancel();
  70. super.dispose();
  71. }
  72. @override
  73. Widget build(BuildContext context) {
  74. final isLightMode =
  75. MediaQuery.of(context).platformBrightness == Brightness.light;
  76. return Scaffold(
  77. body: SingleChildScrollView(
  78. child: Center(
  79. child: Padding(
  80. padding: const EdgeInsets.symmetric(horizontal: 20),
  81. child: Column(
  82. crossAxisAlignment: CrossAxisAlignment.center,
  83. children: [
  84. Stack(
  85. alignment: Alignment.center,
  86. children: [
  87. isLightMode
  88. ? Image.asset(
  89. 'assets/loading_photos_background.png',
  90. color: Colors.white.withOpacity(0.5),
  91. colorBlendMode: BlendMode.modulate,
  92. )
  93. : Image.asset(
  94. 'assets/loading_photos_background_dark.png',
  95. color: Colors.white.withOpacity(0.25),
  96. colorBlendMode: BlendMode.modulate,
  97. ),
  98. const SizedBox(height: 20),
  99. Column(
  100. children: [
  101. const SizedBox(height: 50),
  102. Lottie.asset(
  103. 'assets/loadingGalleryLottie.json',
  104. height: 400,
  105. ),
  106. ],
  107. )
  108. ],
  109. ),
  110. Text(
  111. "Loading your photos...",
  112. style: TextStyle(
  113. color: Theme.of(context).colorScheme.subTextColor,
  114. ),
  115. ),
  116. const SizedBox(height: 54),
  117. Column(
  118. children: [
  119. Row(
  120. mainAxisAlignment: MainAxisAlignment.start,
  121. children: [
  122. Text(
  123. "Did you know?",
  124. style: Theme.of(context).textTheme.headline6.copyWith(
  125. color: Theme.of(context).colorScheme.greenText,
  126. ),
  127. ),
  128. ],
  129. ),
  130. const SizedBox(
  131. height: 16,
  132. ),
  133. SizedBox(
  134. height: 175,
  135. child: Stack(
  136. children: [
  137. PageView.builder(
  138. scrollDirection: Axis.vertical,
  139. controller: _pageController,
  140. itemBuilder: (context, index) {
  141. return _getMessage(_messages[index]);
  142. },
  143. itemCount: _messages.length,
  144. physics: NeverScrollableScrollPhysics(),
  145. ),
  146. Positioned(
  147. bottom: 0,
  148. left: 0,
  149. right: 0,
  150. child: BottomShadowWidget(),
  151. )
  152. ],
  153. ),
  154. ),
  155. ],
  156. ),
  157. ],
  158. ),
  159. ),
  160. ),
  161. ),
  162. );
  163. }
  164. Widget _getMessage(String text) {
  165. return Text(
  166. text,
  167. textAlign: TextAlign.start,
  168. style: Theme.of(context)
  169. .textTheme
  170. .headline5
  171. .copyWith(color: Theme.of(context).colorScheme.defaultTextColor),
  172. );
  173. }
  174. }