Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mobile App
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
Mobile App
Commits
a13f1396
Commit
a13f1396
authored
5 years ago
by
Markin Igor
Browse files
Options
Downloads
Patches
Plain Diff
Introduce app modes. Refactor screens. Hide authorize button for standalone mode.
parent
b67d77eb
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Resolve "Rework auth flow."
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/src/app.dart
+17
-11
17 additions, 11 deletions
lib/src/app.dart
lib/src/screens/home.dart
+45
-14
45 additions, 14 deletions
lib/src/screens/home.dart
with
62 additions
and
25 deletions
lib/src/app.dart
+
17
−
11
View file @
a13f1396
...
...
@@ -9,6 +9,17 @@ import 'package:shared_preferences/shared_preferences.dart';
import
'package:uni_links/uni_links.dart'
;
enum
AppMode
{
Default
,
Authorization
,
}
enum
Screen
{
App
,
OAuth
,
Dashboard
}
class
App
extends
StatelessWidget
{
Future
<
Widget
>
initApplication
()
async
{
Uri
initialUri
;
...
...
@@ -58,11 +69,12 @@ class MainApp extends StatefulWidget {
class
_MainAppState
extends
State
<
MainApp
>
{
StreamSubscription
_sub
;
String
_appMode
=
""
;
/// "Default" when you open app, "Authorization" when app initiated
/// from third party app
AppMode
_appMode
;
// Url of the app which invoked OAuth
String
_invokerURL
;
String
_host
;
@override
initState
()
{
...
...
@@ -89,22 +101,17 @@ class _MainAppState extends State<MainApp> {
updateAppMode
(
Uri
uri
)
{
if
(
uri
?.
path
==
"/authorize"
)
{
setState
(()
{
_appMode
=
"oauth"
;
_appMode
=
AppMode
.
Authorization
;
_invokerURL
=
uri
.
queryParameters
[
"invokerUrl"
];
});
}
else
{
setState
(()
{
_appMode
=
"app"
;
_appMode
=
AppMode
.
Default
;
});
}
}
setMode
(
String
mode
)
{
setState
(()
{
_appMode
=
mode
;
});
}
@override
Widget
build
(
BuildContext
context
)
{
return
new
Scaffold
(
...
...
@@ -112,7 +119,6 @@ class _MainAppState extends State<MainApp> {
body:
Home
(
mode:
_appMode
,
invokerURL:
_invokerURL
,
setMode:
setMode
,
host:
widget
.
initialHost
)
);
...
...
This diff is collapsed.
Click to expand it.
lib/src/screens/home.dart
+
45
−
14
View file @
a13f1396
...
...
@@ -8,13 +8,18 @@ import 'dart:async';
import
'package:shared_preferences/shared_preferences.dart'
;
import
'../../config.dart'
;
import
'../app.dart'
;
class
Home
extends
StatefulWidget
{
Home
({
@required
this
.
mode
,
@required
this
.
invokerURL
,
@required
this
.
setMode
,
@required
this
.
host
});
final
String
mode
;
Home
({
@required
this
.
mode
,
@required
this
.
invokerURL
,
@required
this
.
host
,
});
final
AppMode
mode
;
final
String
invokerURL
;
final
String
host
;
final
void
Function
(
String
)
setMode
;
@override
_HomeState
createState
()
=
>
_HomeState
();
...
...
@@ -24,24 +29,28 @@ class _HomeState extends State<Home> {
String
_host
=
Config
.
appFlavor
==
Flavor
.
DEVELOPMENT
?
Config
.
HOSTS
[
0
]
:
Config
.
DEFAULT_APP_HOST
;
bool
_hidden
=
true
;
Screen
_currentScreen
=
Screen
.
App
;
@override
initState
()
{
super
.
initState
();
// Set up initial host
if
(
widget
.
host
!=
null
)
{
setState
(()
{
_host
=
widget
.
host
;
});
}
s
how
Mode
(
widget
.
mode
);
s
etScreenBy
Mode
(
widget
.
mode
);
FlutterAppAuthWrapper
.
eventStream
()
.
listen
((
data
)
{
var
token
=
json
.
decode
(
data
.
toString
())[
"access_token"
];
_showAlert
(
token
);
widget
.
setMode
(
""
);
setScreen
(
Screen
.
App
);
},
onError:
(
error
)
{
log
(
"Err
$error
"
);
widget
.
setMode
(
""
);
setScreen
(
Screen
.
App
);
});
Timer
(
...
...
@@ -54,6 +63,25 @@ class _HomeState extends State<Home> {
);
}
setScreen
(
Screen
screen
)
{
if
(
_currentScreen
==
screen
&&
screen
!=
Screen
.
Dashboard
// ATM we can not determine whether dashboard was closed or not, so we avoid this case
)
{
return
;
}
setState
(()
{
_currentScreen
=
screen
;
});
if
(
_currentScreen
==
Screen
.
Dashboard
)
{
openVereign
();
}
else
if
(
_currentScreen
==
Screen
.
OAuth
)
{
startOAuth
();
}
}
Future
<
void
>
_showAlert
(
token
)
{
return
showDialog
<
void
>(
context:
context
,
...
...
@@ -93,17 +121,17 @@ class _HomeState extends State<Home> {
}
if
(
widget
.
mode
!=
oldWidget
.
mode
)
{
s
how
Mode
(
widget
.
mode
);
s
etScreenBy
Mode
(
widget
.
mode
);
}
super
.
didUpdateWidget
(
oldWidget
);
}
s
how
Mode
(
mode
)
{
if
(
mode
==
"app"
)
{
openVereign
(
);
}
else
if
(
mode
==
"oauth"
)
{
s
tartOAuth
(
);
s
etScreenByMode
(
App
Mode
mode
)
{
if
(
mode
==
AppMode
.
Authorization
)
{
setScreen
(
Screen
.
OAuth
);
}
else
if
(
mode
==
AppMode
.
Default
)
{
s
etScreen
(
Screen
.
Dashboard
);
}
}
...
...
@@ -141,10 +169,13 @@ class _HomeState extends State<Home> {
}
var
children
=
<
Widget
>[
_urlButton
(
context
,
"Open Dashboard"
,
openVereign
),
_urlButton
(
context
,
"Authorize with Vereign"
,
startOAuth
)
_urlButton
(
context
,
"Open Dashboard"
,
()
=
>
setScreen
(
Screen
.
Dashboard
)),
];
if
(
widget
.
mode
==
AppMode
.
Authorization
)
{
children
.
add
(
_urlButton
(
context
,
"Authorize with Vereign"
,
()
=
>
setScreen
(
Screen
.
OAuth
)));
}
if
(
Config
.
appFlavor
==
Flavor
.
DEVELOPMENT
)
{
children
.
add
(
wrapInContainer
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment