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

feat(#58): Adiciona controle de visualizacao onboarding #65

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
9 changes: 6 additions & 3 deletions lib/core/data/local/StorageValue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:aranduapp/core/log/Log.dart';

class StorageValue {

static const String _authToken = "auth_token";
static const String _refreshToken = "refresh_token";
static const String _email = "email";
static const String _name = "name";
static const String _viewOnboardingCount = "view_onboarding_count";

static StorageValue? _singleton;
final FlutterSecureStorage storage;
Expand All @@ -15,8 +15,7 @@ class StorageValue {
: storage = const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true));

factory StorageValue.getInstance() =>
_singleton ??= StorageValue._internal();
factory StorageValue.getInstance() => _singleton ??= StorageValue._internal();

Future<void> _setValue(String key, String value) async {
try {
Expand All @@ -39,11 +38,15 @@ class StorageValue {
Future<void> setRefreshToken(String token) => _setValue(_refreshToken, token);
Future<void> setEmail(String email) => _setValue(_email, email);
Future<void> setName(String name) => _setValue(_name, name);
Future<void> setViewOnboardingCount(int count) =>
_setValue(_viewOnboardingCount, count.toString());

Future<String?> getAuthToken() => _getValue(_authToken);
Future<String?> getRefreshToken() => _getValue(_refreshToken);
Future<String?> getEmail() => _getValue(_email);
Future<String?> getName() => _getValue(_name);
Future<int?> getOnboardingCount() async =>
int.tryParse(await _getValue(_viewOnboardingCount) ?? '');

Future<void> clear() async {
try {
Expand Down
18 changes: 14 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import 'package:aranduapp/config/ThemeApp.dart';
import 'package:aranduapp/ui/login/view/LoginView.dart';
import 'package:aranduapp/ui/welcome/view/WelcomeView.dart';
import 'package:aranduapp/ui/onboarding/viewModel/onboarding_view_model.dart';
import 'package:flutter/material.dart';
import 'package:aranduapp/core/data/local/StorageValue.dart';

void main() {
runApp(const MyApp());
void main() async {
WidgetsFlutterBinding.ensureInitialized();

await OnboardingViewModel().incrementNumber();

int viewCount = await StorageValue.getInstance().getOnboardingCount() ?? 0;

runApp(MyApp(viewCount: viewCount));
}

class MyApp extends StatelessWidget {
const MyApp({super.key});
final int viewCount;

const MyApp({super.key, required this.viewCount});

@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeApp.themeData(),
darkTheme: ThemeApp.darkThemeData(),
debugShowCheckedModeBanner: false,
home: WelcomeView(),
home: viewCount >= 3 ? const Login() : WelcomeView(),
);
}
}
13 changes: 13 additions & 0 deletions lib/ui/onboarding/viewModel/onboarding_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:aranduapp/ui/login/view/LoginView.dart';
import 'package:flutter/material.dart';
import 'package:aranduapp/core/data/local/StorageValue.dart';

class OnboardingViewModel extends ChangeNotifier {
final PageController pageController = PageController();
Expand All @@ -23,4 +24,16 @@ class OnboardingViewModel extends ChangeNotifier {
MaterialPageRoute(builder: (context) => const Login()),
);
}

Future<void> incrementNumber() async {
try {
final storage = StorageValue.getInstance();
int currentCount = await storage.getOnboardingCount() ?? 0;
currentCount++;
await storage.setViewOnboardingCount(currentCount);
debugPrint('View count incremented to: $currentCount');
} catch (e) {
debugPrint('Error incrementing view count: $e');
}
}
}
Loading