diff --git a/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_view.dart b/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_view.dart index fa7b8c9f9..f5b7dcaad 100644 --- a/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_view.dart +++ b/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_view.dart @@ -89,7 +89,7 @@ class NewsTutorialView extends StatelessWidget { builder: (context, model, child) => Scaffold( backgroundColor: const Color(0xFF0a0a23), body: FutureBuilder( - future: model.initState(refId), + future: model.tutorialFuture, builder: (context, snapshot) { if (snapshot.hasData) { var tutorial = snapshot.data; @@ -131,37 +131,38 @@ class NewsTutorialView extends StatelessWidget { ) { return Align( alignment: Alignment.bottomCenter, - child: SizedBox( - height: 75, - width: 300, - child: ListView( - physics: const NeverScrollableScrollPhysics(), - controller: model.bottomButtonController, - children: [ - Row( - children: [ - Container( - height: 150, - ), - NewsBookmarkViewWidget(tutorial: tutorial), - const SizedBox( - height: 35, - child: VerticalDivider( - color: Colors.white, - width: 0, + child: SafeArea( + child: AnimatedSlide( + offset: model.showBottomButtons ? Offset.zero : const Offset(0, 2.0), + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + child: Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: SizedBox( + height: 50, + width: 300, + child: Row( + children: [ + NewsBookmarkViewWidget(tutorial: tutorial), + const SizedBox( + height: 35, + child: VerticalDivider( + color: Colors.white, + width: 0, + ), ), - ), - BottomButton( - label: context.t.share, - icon: Icons.share, - onPressed: () { - Share.share('${tutorial.title}\n\n${tutorial.url}'); - }, - rightSided: true, - ) - ], + BottomButton( + label: context.t.share, + icon: Icons.share, + onPressed: () { + Share.share('${tutorial.title}\n\n${tutorial.url}'); + }, + rightSided: true, + ) + ], + ), ), - ], + ), ), ), ); diff --git a/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_viewmodel.dart b/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_viewmodel.dart index 06f33f75c..293190dc5 100644 --- a/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_viewmodel.dart +++ b/mobile-app/lib/ui/views/news/news-tutorial/news_tutorial_viewmodel.dart @@ -14,7 +14,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:stacked/stacked.dart'; class NewsTutorialViewModel extends BaseViewModel { - late Future _tutorialFuture; + Future? _tutorialFuture; final _newsApiService = locator(); Future? get tutorialFuture => _tutorialFuture; @@ -22,8 +22,15 @@ class NewsTutorialViewModel extends BaseViewModel { final ScrollController _scrollController = ScrollController(); ScrollController get scrollController => _scrollController; - final ScrollController _bottomButtonController = ScrollController(); - ScrollController get bottomButtonController => _bottomButtonController; + bool _showBottomButtons = false; + bool get showBottomButtons => _showBottomButtons; + + set showBottomButtons(bool value) { + if (_showBottomButtons != value) { + _showBottomButtons = value; + notifyListeners(); + } + } bool _showToTopButton = false; bool get showToTopButton => _showToTopButton; @@ -43,15 +50,13 @@ class NewsTutorialViewModel extends BaseViewModel { return Tutorial.toPostFromJson(decodedJson); } - Future initState(id) async { - handleBottomButtonAnimation(); - handleToTopButton(); - - // if (await _developerService.developmentMode()) { - // return readFromFiles(); - // } else { - // } - return fetchTutorial(id); + Future initState(id) { + if (_tutorialFuture == null) { + handleBottomButtonAnimation(); + handleToTopButton(); + _tutorialFuture = fetchTutorial(id); + } + return _tutorialFuture!; } Future handleToTopButton() async { @@ -87,17 +92,9 @@ class NewsTutorialViewModel extends BaseViewModel { double oldScrollPos = prefs.getDouble('position') as double; if (_scrollController.offset <= oldScrollPos) { - _bottomButtonController.animateTo( - _bottomButtonController.position.maxScrollExtent - 50, - duration: const Duration(milliseconds: 1000), - curve: Curves.easeInOut, - ); + showBottomButtons = true; } else { - _bottomButtonController.animateTo( - 0, - duration: const Duration(milliseconds: 1000), - curve: Curves.easeInOut, - ); + showBottomButtons = false; } Timer(const Duration(seconds: 2), () async { if (_scrollController.hasClients) { @@ -112,15 +109,8 @@ class NewsTutorialViewModel extends BaseViewModel { // this means we need to animate it manually. Future.delayed( const Duration(seconds: 1), - () => { - if (_bottomButtonController.hasClients) - { - _bottomButtonController.animateTo( - _bottomButtonController.position.maxScrollExtent - 50, - duration: const Duration(milliseconds: 1000), - curve: Curves.easeInOut, - ) - } + () { + showBottomButtons = true; }, ); } @@ -175,7 +165,6 @@ class NewsTutorialViewModel extends BaseViewModel { Future removeScrollPosition() async { SharedPreferences prefs = await SharedPreferences.getInstance(); _scrollController.dispose(); - _bottomButtonController.dispose(); await prefs.remove('position'); }