anyway/frontend/lib/pages/onboarding.dart
Remy Moll 03cf58ce43
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m36s
Run linting on the backend code / Build (pull_request) Successful in 28s
Run testing on the backend code / Build (pull_request) Failing after 18m37s
Build and release debug APK / Build APK (pull_request) Failing after 4m42s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 31s
revamped onboarding
2025-02-25 19:18:44 +01:00

166 lines
5.8 KiB
Dart

import 'dart:ui';
import 'package:anyway/constants.dart';
import 'package:anyway/modules/onbarding_agreement_card.dart';
import 'package:anyway/modules/onboarding_card.dart';
import 'package:anyway/pages/new_trip_location.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
List<Widget> onboardingCards = [
const OnboardingCard(
title: "Welcome to anyway!",
description: "Anyway helps you plan a city trip that suits your wishes.",
imagePath: "assets/cld-server.svg"
),
const OnboardingCard(
title: "Do your thing",
description: "Bored by churches? No problem! Hate shopping? No worries! Instead of suggesting the generic trips that bore you, anyway will try to give you recommendations that really suit you.",
imagePath: "assets/con-drill.svg"
),
const OnboardingCard(
title: "Change your mind",
description: "Feet get sore, the weather changes. Anyway understands that! Move or remove destinations, visit hidden gems along your journey, do your own thing. Anyway adapts to your spontaneous decisions.",
imagePath: "assets/cel-snow-globe.svg"
),
const OnboardingCard(
title: "Feeling lost?",
description: "Whenever you are confused or need help with the app, look out for the question mark in the top right corner. Help is just a tap away!",
imagePath: "assets/gen-lifebelt.svg"
),
];
class OnboardingPage extends StatefulWidget {
const OnboardingPage({super.key});
@override
State<OnboardingPage> createState() => _OnboardingPageState();
}
class _OnboardingPageState extends State<OnboardingPage> {
final PageController _controller = PageController();
late List<Widget> fullCards;
@override
Widget build(BuildContext context) {
Widget agreementCard = OnboardingAgreementCard(
title: "The annoying stuff",
description: "By using anyway, you agree to our terms and conditions and privacy policy. We don't use cookies or tracking, we don't store the data you submit. We are not responsible for any damage or loss caused by using anyway.",
imagePath: "assets/con-warning.svg",
agreementTextPath: "assets/terms_and_conditions.md",
onAgreementChanged: onAgreementChanged,
);
// need to add the agreement from within the function because it needs to be able to call setState
fullCards = onboardingCards + [agreementCard];
return Scaffold(
body: Stack(
children: [
AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Stack(
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: APP_GRADIENT.colors,
stops: [
(_controller.hasClients ? (_controller.page ?? _controller.initialPage) : _controller.initialPage) / onboardingCards.length,
(_controller.hasClients ? (_controller.page ?? _controller.initialPage) + 1 : _controller.initialPage + 1) / onboardingCards.length,
],
),
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
color: Colors.black.withValues(alpha: 0.2)
),
),
],
);
},
),
PageView(
controller: _controller,
children: List.generate(
fullCards.length,
(index) {
return Container(
alignment: Alignment.center,
child: fullCards[index],
);
}
),
),
],
),
floatingActionButton: nextButton(_controller)
);
}
Widget nextButton(PageController controller) => AnimatedBuilder(
animation: _controller,
builder: (context, child) {
if ((_controller.hasClients ? (_controller.page ?? _controller.initialPage) : 0) != fullCards.length - 1) {
return FloatingActionButton.extended(
onPressed: () {
controller.nextPage(duration: Duration(milliseconds: 500), curve: Curves.ease);
},
label: Icon(Icons.arrow_forward)
);
} else {
// only allow the user to proceed if they have agreed to the terms and conditions
Future<bool> hasAgreed = SharedPreferences.getInstance().then(
(SharedPreferences prefs) {
return prefs.getBool('TC_agree') ?? false;
}
);
return FutureBuilder(
future: hasAgreed,
builder: (context, snapshot){
if (snapshot.hasData && snapshot.data!) {
return FloatingActionButton.extended(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NewTripPage()
)
);
},
label: const Row(
children: [
Text("Start planning!"),
Padding(padding: EdgeInsets.only(right: 8.0)),
Icon(Icons.map_outlined)
],
)
);
} else {
return Container();
}
}
);
}
}
);
void onAgreementChanged(bool value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('TC_agree', value);
// Update the state of the OnboardingPage
setState(() {});
}
}