Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared preferences added to store whether the user has already seen t… #16

Merged
merged 1 commit into from
Oct 31, 2021
Merged
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
1 change: 1 addition & 0 deletions .fvm/flutter_sdk
4 changes: 4 additions & 0 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"flutterSdkVersion": "2.5.0",
"flavors": {}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
28 changes: 28 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1635364878197</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/default-java
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
6 changes: 6 additions & 0 deletions android/app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
34 changes: 34 additions & 0 deletions android/app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1635364878213</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 2 additions & 0 deletions android/app/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
7 changes: 6 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Index"
Expand Down Expand Up @@ -46,5 +51,5 @@
android:value="2" />
</application>

<uses-permission android:name="android.permission.INTERNET" />

</manifest>
45 changes: 44 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import 'package:get/get.dart';
import 'package:index/utils/theming.dart';

import 'package:index/views/pages/onboarding_screen.dart';
import 'package:index/views/pages/front-page.dart';
import 'package:path_provider/path_provider.dart';

import 'models/articles-data-hive_model.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.storage.request().isGranted;
putLumberdashToWork(withClients: [ColorizeLumberdash()]);

// Initialise Hive
Expand All @@ -21,7 +25,15 @@ void main() async {
Hive.registerAdapter(ArticlesDataHiveModelAdapter());
await Hive.openBox<ArticlesDataHiveModel>('articlesData');

runApp(IndexApp());
var onboardValue;
final onboardprefs = await SharedPreferences.getInstance();
onboardValue = onboardprefs.getInt('onboardState');

if (onboardValue == 1) {
runApp(IndexApp());
} else {
runApp(OnboardApp());
}
}

/// Sets up the highest quality possible display mode for the app
Expand Down Expand Up @@ -56,6 +68,37 @@ class _IndexAppState extends State<IndexApp> with WidgetsBindingObserver {
super.dispose();
}

@override
Widget build(BuildContext context) {
return GetMaterialApp(
theme: Theming.lightTheme(),
darkTheme: Theming.darkTheme(),
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
home: FrontPage(),
);
}
}

class OnboardApp extends StatefulWidget {
@override
_OnboardAppState createState() => _OnboardAppState();
}

class _OnboardAppState extends State<OnboardApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
initDisplayMode();
}

@override
dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
Widget build(BuildContext context) {
return GetMaterialApp(
Expand Down
26 changes: 18 additions & 8 deletions lib/views/pages/onboarding_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:index/utils/onboarding_styles.dart';
import 'package:index/views/pages/front-page.dart';
import 'package:shared_preferences/shared_preferences.dart';

class OnboardingScreen extends StatefulWidget {
@override
Expand Down Expand Up @@ -61,10 +62,15 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
Container(
alignment: Alignment.centerRight,
child: FlatButton(
onPressed: () => Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => FrontPage())),
onPressed: () async {
final onboardprefs =
await SharedPreferences.getInstance();
onboardprefs.setInt('onboardState', 1);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => FrontPage()));
},
child: Text(
'Skip',
style: TextStyle(
Expand Down Expand Up @@ -218,10 +224,14 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
width: double.infinity,
color: Colors.white,
child: GestureDetector(
onTap: () => Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => FrontPage())),
onTap: () async {
final onboardprefs = await SharedPreferences.getInstance();
onboardprefs.setInt('onboardState', 1);
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => FrontPage()));
},
child: Center(
child: Padding(
padding: EdgeInsets.only(bottom: 30.0),
Expand Down
56 changes: 56 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.3"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -590,6 +604,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shelf:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies:
timeago: ^3.1.0
url_launcher: ^6.0.12
webview_flutter: ^2.1.1
shared_preferences: ^2.0.8
permission_handler: ^6.1.3

dev_dependencies:
build_runner: ^2.1.4
Expand Down