Skip to content

Commit

Permalink
Merge pull request #188 from Sh1vT/getting_started_page_appears_once
Browse files Browse the repository at this point in the history
the getting started page now appears only once in the app's lifetime
  • Loading branch information
sapatevaibhav authored Jun 23, 2024
2 parents 2e54c35 + 61ea713 commit cceddc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/landing_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:learn/utils/route/route_constant.dart';
import 'package:shared_preferences/shared_preferences.dart';

class LandingPage extends StatefulWidget {
const LandingPage({
Expand All @@ -22,7 +23,6 @@ class _LandingPageState extends State<LandingPage> {
padding: const EdgeInsets.all(20),
child: Column(
children: [

Center(
child: Container(
width: width,
Expand All @@ -39,14 +39,12 @@ class _LandingPageState extends State<LandingPage> {
child: SizedBox(
child: DefaultTextStyle(
style: TextStyle(

fontSize: width / 19,
),
child: AnimatedTextKit(
animatedTexts: [
ColorizeAnimatedText(
'Learn',

textStyle: TextStyle(
fontSize: width / 12,
fontWeight: FontWeight.w900),
Expand All @@ -69,7 +67,6 @@ class _LandingPageState extends State<LandingPage> {
child: Text(
"Learning Made Easy",
style: TextStyle(

fontWeight: FontWeight.w400, fontSize: width / 18),
),
),
Expand All @@ -87,7 +84,14 @@ class _LandingPageState extends State<LandingPage> {
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
)),
onPressed: () {
onPressed: () async {
//bool check initiates
final SharedPreferences prefs =
await SharedPreferences.getInstance();
if (!prefs.containsKey('visitedGettingStartedPageOnce') || prefs.getBool('visitedGettingStartedPageOnce')==false) { //if it never existed or if it is false somehow
await prefs.setBool(
'visitedGettingStartedPageOnce', true); //set to true
}
Navigator.popAndPushNamed(
context,
AllRoutesConstant.mainhomeRoute,
Expand Down
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import 'package:flutter/material.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:learn/landing_page.dart';
import 'package:learn/pages/main_home.dart';
import 'package:learn/utils/route/routes.dart';
import 'package:learn/theme_provider.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

DateTime? currentBackPressTime;
bool visitedGettingStartedPageOnceBool=false; //to store the value of

void main() async {
WidgetsFlutterBinding.ensureInitialized();
final savedThemeMode = await AdaptiveTheme.getThemeMode();
final prefs = await SharedPreferences.getInstance();
visitedGettingStartedPageOnceBool = prefs.getBool('visitedGettingStartedPageOnce')??false; //if its is null i.e first time then set to false

runApp(
ChangeNotifierProvider(
create: (context) => ThemeProvider(),
Expand All @@ -33,7 +39,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: themeProvider.themeMode,
home: const LandingPage(),
home: visitedGettingStartedPageOnceBool? const MainHome(): const LandingPage(), //if page opened for first time , show landing page (getting started page), else show home page
onGenerateRoute: Routers.generateRoute,
);
},
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
flutter_bloc: ^8.1.5
animated_text_kit: ^4.2.2
font_awesome_flutter: ^10.1.0
shared_preferences: ^2.2.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit cceddc7

Please sign in to comment.