Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-flutter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-flutter
Commits
860b6510
Commit
860b6510
authored
Aug 13, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle login session on android
parent
9cd799d3
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
83 additions
and
97 deletions
+83
-97
kotlin-compiler-16411864663037035601.salive
...tlin/sessions/kotlin-compiler-16411864663037035601.salive
+0
-0
main.dart
lib/main.dart
+8
-10
auth_provider.dart
lib/src/providers/auth_provider.dart
+8
-11
generated_plugin_registrant.cc
linux/flutter/generated_plugin_registrant.cc
+0
-4
generated_plugins.cmake
linux/flutter/generated_plugins.cmake
+0
-1
GeneratedPluginRegistrant.swift
macos/Flutter/GeneratedPluginRegistrant.swift
+2
-2
pubspec.lock
pubspec.lock
+64
-64
pubspec.yaml
pubspec.yaml
+1
-1
generated_plugin_registrant.cc
windows/flutter/generated_plugin_registrant.cc
+0
-3
generated_plugins.cmake
windows/flutter/generated_plugins.cmake
+0
-1
No files found.
android/.kotlin/sessions/kotlin-compiler-16411864663037035601.salive
0 → 100644
View file @
860b6510
lib/main.dart
View file @
860b6510
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:google_fonts/google_fonts.dart'
;
import
'package:google_fonts/google_fonts.dart'
;
import
'package:library_app/src/screens/profile_edit_screen.dart'
;
import
'package:library_app/src/screens/profile_edit_screen.dart'
;
...
@@ -12,8 +13,11 @@ import 'package:library_app/src/providers/book_provider.dart';
...
@@ -12,8 +13,11 @@ import 'package:library_app/src/providers/book_provider.dart';
import
'package:library_app/src/screens/form_screen.dart'
;
import
'package:library_app/src/screens/form_screen.dart'
;
import
'package:library_app/src/screens/list/list_screen.dart'
;
import
'package:library_app/src/screens/list/list_screen.dart'
;
void
main
(
)
{
void
main
(
)
async
{
runApp
(
const
LibraryApp
());
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
final
isAuthenticated
=
prefs
.
getString
(
'access_token'
)
!=
null
;
runApp
(
isAuthenticated
?
const
LibraryApp
()
:
const
LoginScreen
());
}
}
class
LibraryApp
extends
StatefulWidget
{
class
LibraryApp
extends
StatefulWidget
{
...
@@ -32,17 +36,11 @@ class _LibraryApp extends State<LibraryApp> {
...
@@ -32,17 +36,11 @@ class _LibraryApp extends State<LibraryApp> {
routes:
[
routes:
[
GoRoute
(
GoRoute
(
path:
'/'
,
path:
'/'
,
builder:
(
context
,
state
)
=>
builder:
(
context
,
state
)
=>
const
ListScreen
(),
Provider
.
of
<
AuthProvider
>(
context
).
isAuthenticated
?
const
ListScreen
()
:
const
LoginScreen
(),
),
),
GoRoute
(
GoRoute
(
path:
'/sign-up'
,
path:
'/sign-up'
,
builder:
(
context
,
state
)
=>
builder:
(
context
,
state
)
=>
const
SignUpScreen
(),
Provider
.
of
<
AuthProvider
>(
context
).
isAuthenticated
?
const
ListScreen
()
:
const
SignUpScreen
(),
),
),
GoRoute
(
GoRoute
(
path:
'/reset-password'
,
path:
'/reset-password'
,
...
...
lib/src/providers/auth_provider.dart
View file @
860b6510
import
'dart:convert'
;
import
'dart:convert'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:
flutter_secure_storage/flutter_secure_storage
.dart'
;
import
'package:
shared_preferences/shared_preferences
.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
...
@@ -9,13 +9,10 @@ import 'package:library_app/src/models/token.dart';
...
@@ -9,13 +9,10 @@ import 'package:library_app/src/models/token.dart';
import
'package:library_app/src/models/user.dart'
;
import
'package:library_app/src/models/user.dart'
;
class
AuthProvider
with
ChangeNotifier
{
class
AuthProvider
with
ChangeNotifier
{
final
storage
=
const
FlutterSecureStorage
();
String
baseUrl
=
'https://ilhammaulana.pythonanywhere.com/api/v1'
;
String
baseUrl
=
'https://ilhammaulana.pythonanywhere.com/api/v1'
;
String
?
message
;
String
?
message
;
User
?
user
;
User
?
user
;
bool
isAuthenticated
=
false
;
bool
invalidUsernameOrPassword
=
false
;
bool
invalidUsernameOrPassword
=
false
;
List
<
dynamic
>?
memberLoans
;
List
<
dynamic
>?
memberLoans
;
...
@@ -38,11 +35,13 @@ class AuthProvider with ChangeNotifier {
...
@@ -38,11 +35,13 @@ class AuthProvider with ChangeNotifier {
List
<
dynamic
>?
overduedLoans
;
List
<
dynamic
>?
overduedLoans
;
Future
<
void
>
storeAccessToken
(
String
accessToken
)
async
{
Future
<
void
>
storeAccessToken
(
String
accessToken
)
async
{
await
storage
.
write
(
key:
'access_token'
,
value:
accessToken
);
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
await
prefs
.
setString
(
'access_token'
,
accessToken
);
}
}
Future
<
String
?>
getAccessToken
()
async
{
Future
<
String
?>
getAccessToken
()
async
{
return
await
storage
.
read
(
key:
'access_token'
);
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
return
prefs
.
getString
(
'access_token'
);
}
}
void
setLoading
(
bool
value
)
{
void
setLoading
(
bool
value
)
{
...
@@ -67,7 +66,6 @@ class AuthProvider with ChangeNotifier {
...
@@ -67,7 +66,6 @@ class AuthProvider with ChangeNotifier {
overduedLoans
=
null
;
overduedLoans
=
null
;
totalPages
=
null
;
totalPages
=
null
;
isAuthenticated
=
false
;
invalidUsernameOrPassword
=
false
;
invalidUsernameOrPassword
=
false
;
filterByUpcoming
=
false
;
filterByUpcoming
=
false
;
filterByOverdued
=
false
;
filterByOverdued
=
false
;
...
@@ -100,7 +98,6 @@ class AuthProvider with ChangeNotifier {
...
@@ -100,7 +98,6 @@ class AuthProvider with ChangeNotifier {
String
token
=
Token
.
fromJson
(
data
)!.
key
;
String
token
=
Token
.
fromJson
(
data
)!.
key
;
await
storeAccessToken
(
token
);
await
storeAccessToken
(
token
);
isAuthenticated
=
true
;
setInvalidUsernameOrPassword
(
false
);
setInvalidUsernameOrPassword
(
false
);
debugPrint
(
"Login successful
$token
"
);
debugPrint
(
"Login successful
$token
"
);
...
@@ -133,7 +130,8 @@ class AuthProvider with ChangeNotifier {
...
@@ -133,7 +130,8 @@ class AuthProvider with ChangeNotifier {
);
);
if
(
response
.
statusCode
==
200
)
{
if
(
response
.
statusCode
==
200
)
{
await
storage
.
delete
(
key:
'token'
);
SharedPreferences
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
remove
(
'access_token'
);
resetAllState
();
resetAllState
();
}
else
{
}
else
{
debugPrint
(
"Logout failed:
${response.statusCode}
${response.body}
"
);
debugPrint
(
"Logout failed:
${response.statusCode}
${response.body}
"
);
...
@@ -165,7 +163,6 @@ class AuthProvider with ChangeNotifier {
...
@@ -165,7 +163,6 @@ class AuthProvider with ChangeNotifier {
final
data
=
jsonDecode
(
response
.
body
);
final
data
=
jsonDecode
(
response
.
body
);
String
token
=
Token
.
fromJson
(
data
)!.
key
;
String
token
=
Token
.
fromJson
(
data
)!.
key
;
storeAccessToken
(
token
);
storeAccessToken
(
token
);
isAuthenticated
=
true
;
message
=
null
;
message
=
null
;
if
(
context
.
mounted
)
{
if
(
context
.
mounted
)
{
...
@@ -482,7 +479,7 @@ class AuthProvider with ChangeNotifier {
...
@@ -482,7 +479,7 @@ class AuthProvider with ChangeNotifier {
// for admin or librarian
// for admin or librarian
Future
<
void
>
getLoans
(
String
?
type
)
async
{
Future
<
void
>
getLoans
(
String
?
type
)
async
{
final
token
=
await
storage
.
read
(
key:
'access_token'
);
final
token
=
await
getAccessToken
(
);
String
url
=
"
$baseUrl
/book-loans"
;
String
url
=
"
$baseUrl
/book-loans"
;
if
(
type
==
"upcoming"
)
{
if
(
type
==
"upcoming"
)
{
url
+=
'?near_outstanding=True'
;
url
+=
'?near_outstanding=True'
;
...
...
linux/flutter/generated_plugin_registrant.cc
View file @
860b6510
...
@@ -6,10 +6,6 @@
...
@@ -6,10 +6,6 @@
#include "generated_plugin_registrant.h"
#include "generated_plugin_registrant.h"
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
void
fl_register_plugins
(
FlPluginRegistry
*
registry
)
{
void
fl_register_plugins
(
FlPluginRegistry
*
registry
)
{
g_autoptr
(
FlPluginRegistrar
)
flutter_secure_storage_linux_registrar
=
fl_plugin_registry_get_registrar_for_plugin
(
registry
,
"FlutterSecureStorageLinuxPlugin"
);
flutter_secure_storage_linux_plugin_register_with_registrar
(
flutter_secure_storage_linux_registrar
);
}
}
linux/flutter/generated_plugins.cmake
View file @
860b6510
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#
#
list
(
APPEND FLUTTER_PLUGIN_LIST
list
(
APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
)
)
list
(
APPEND FLUTTER_FFI_PLUGIN_LIST
list
(
APPEND FLUTTER_FFI_PLUGIN_LIST
...
...
macos/Flutter/GeneratedPluginRegistrant.swift
View file @
860b6510
...
@@ -5,10 +5,10 @@
...
@@ -5,10 +5,10 @@
import
FlutterMacOS
import
FlutterMacOS
import
Foundation
import
Foundation
import
flutter_secure_storage_macos
import
path_provider_foundation
import
path_provider_foundation
import
shared_preferences_foundation
func
RegisterGeneratedPlugins
(
registry
:
FlutterPluginRegistry
)
{
func
RegisterGeneratedPlugins
(
registry
:
FlutterPluginRegistry
)
{
FlutterSecureStoragePlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"FlutterSecureStoragePlugin"
))
PathProviderPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"PathProviderPlugin"
))
PathProviderPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"PathProviderPlugin"
))
SharedPreferencesPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"SharedPreferencesPlugin"
))
}
}
pubspec.lock
View file @
860b6510
...
@@ -81,6 +81,14 @@ packages:
...
@@ -81,6 +81,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "2.1.3"
version: "2.1.3"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
flutter:
flutter:
dependency: "direct main"
dependency: "direct main"
description: flutter
description: flutter
...
@@ -94,54 +102,6 @@ packages:
...
@@ -94,54 +102,6 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "4.0.0"
version: "4.0.0"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
sha256: "165164745e6afb5c0e3e3fcc72a012fb9e58496fb26ffb92cf22e16a821e85d0"
url: "https://pub.dev"
source: hosted
version: "9.2.2"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
sha256: "1693ab11121a5f925bbea0be725abfcfbbcf36c1e29e571f84a0c0f436147a81"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
sha256: cf91ad32ce5adef6fba4d736a542baca9daf3beac4db2d04be350b87f69ac4a8
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_secure_storage_web:
dependency: transitive
description:
name: flutter_secure_storage_web
sha256: f4ebff989b4f07b2656fb16b47852c0aab9fed9b4ec1c70103368337bc1886a9
url: "https://pub.dev"
source: hosted
version: "1.2.1"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709
url: "https://pub.dev"
source: hosted
version: "3.1.2"
flutter_svg:
flutter_svg:
dependency: "direct main"
dependency: "direct main"
description:
description:
...
@@ -200,14 +160,6 @@ packages:
...
@@ -200,14 +160,6 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "0.19.0"
version: "0.19.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
leak_tracker:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -376,6 +328,62 @@ packages:
...
@@ -376,6 +328,62 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "6.1.2"
version: "6.1.2"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
sha256: c272f9cabca5a81adc9b0894381e9c1def363e980f960fa903c604c471b22f68
url: "https://pub.dev"
source: hosted
version: "2.3.1"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: a7e8467e9181cef109f601e3f65765685786c1a738a83d7fbbde377589c0d974
url: "https://pub.dev"
source: hosted
version: "2.3.1"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: c4b35f6cb8f63c147312c054ce7c2254c8066745125264f0c88739c417fc9d9f
url: "https://pub.dev"
source: hosted
version: "2.5.2"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e
url: "https://pub.dev"
source: hosted
version: "2.4.2"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
sky_engine:
sky_engine:
dependency: transitive
dependency: transitive
description: flutter
description: flutter
...
@@ -485,14 +493,6 @@ packages:
...
@@ -485,14 +493,6 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "1.0.0"
version: "1.0.0"
win32:
dependency: transitive
description:
name: win32
sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a"
url: "https://pub.dev"
source: hosted
version: "5.5.4"
xdg_directories:
xdg_directories:
dependency: transitive
dependency: transitive
description:
description:
...
...
pubspec.yaml
View file @
860b6510
...
@@ -40,8 +40,8 @@ dependencies:
...
@@ -40,8 +40,8 @@ dependencies:
intl
:
^0.19.0
intl
:
^0.19.0
provider
:
^6.1.2
provider
:
^6.1.2
http
:
^1.2.2
http
:
^1.2.2
flutter_secure_storage
:
^9.2.2
go_router
:
^14.2.1
go_router
:
^14.2.1
shared_preferences
:
^2.3.1
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
windows/flutter/generated_plugin_registrant.cc
View file @
860b6510
...
@@ -6,9 +6,6 @@
...
@@ -6,9 +6,6 @@
#include "generated_plugin_registrant.h"
#include "generated_plugin_registrant.h"
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
void
RegisterPlugins
(
flutter
::
PluginRegistry
*
registry
)
{
void
RegisterPlugins
(
flutter
::
PluginRegistry
*
registry
)
{
FlutterSecureStorageWindowsPluginRegisterWithRegistrar
(
registry
->
GetRegistrarForPlugin
(
"FlutterSecureStorageWindowsPlugin"
));
}
}
windows/flutter/generated_plugins.cmake
View file @
860b6510
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#
#
list
(
APPEND FLUTTER_PLUGIN_LIST
list
(
APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
)
)
list
(
APPEND FLUTTER_FFI_PLUGIN_LIST
list
(
APPEND FLUTTER_FFI_PLUGIN_LIST
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment