Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NewsTutorialView extends StatelessWidget {
builder: (context, model, child) => Scaffold(
backgroundColor: const Color(0xFF0a0a23),
body: FutureBuilder<Tutorial>(
future: model.initState(refId),
future: model.tutorialFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
var tutorial = snapshot.data;
Expand Down Expand Up @@ -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,
)
],
),
),
],
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';

class NewsTutorialViewModel extends BaseViewModel {
late Future<Tutorial> _tutorialFuture;
Future<Tutorial>? _tutorialFuture;
final _newsApiService = locator<NewsApiService>();

Future<Tutorial>? get tutorialFuture => _tutorialFuture;

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;
Expand All @@ -43,15 +50,13 @@ class NewsTutorialViewModel extends BaseViewModel {
return Tutorial.toPostFromJson(decodedJson);
}

Future<Tutorial> initState(id) async {
handleBottomButtonAnimation();
handleToTopButton();

// if (await _developerService.developmentMode()) {
// return readFromFiles();
// } else {
// }
return fetchTutorial(id);
Future<Tutorial> initState(id) {
if (_tutorialFuture == null) {
handleBottomButtonAnimation();
handleToTopButton();
_tutorialFuture = fetchTutorial(id);
}
return _tutorialFuture!;
}

Future<void> handleToTopButton() async {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
},
);
}
Expand Down Expand Up @@ -175,7 +165,6 @@ class NewsTutorialViewModel extends BaseViewModel {
Future<void> removeScrollPosition() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
_scrollController.dispose();
_bottomButtonController.dispose();

await prefs.remove('position');
}
Expand Down