Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mobile App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Merge requests
!2
Resolve "Rework auth flow."
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Rework auth flow."
5-rework-auth-cancelation-flow
into
master
Overview
0
Commits
7
Pipelines
0
Changes
4
Merged
Igor Markin
requested to merge
5-rework-auth-cancelation-flow
into
master
5 years ago
Overview
0
Commits
7
Pipelines
0
Changes
4
Expand
Closes
#5 (closed)
Edited
5 years ago
by
Igor Markin
0
0
Merge request reports
Compare
master
version 3
6fca8e5c
5 years ago
version 2
675f7da0
5 years ago
version 1
08a8d51f
5 years ago
master (base)
and
version 2
latest version
f336f4ec
7 commits,
5 years ago
version 3
6fca8e5c
5 commits,
5 years ago
version 2
675f7da0
4 commits,
5 years ago
version 1
08a8d51f
3 commits,
5 years ago
4 files
+
198
−
139
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
lib/src/screens/home.dart
+
23
−
125
Options
import
'package:flutter/material.dart'
;
import
'package:flutter_web_browser/flutter_web_browser.dart'
;
import
'package:flutter_app_auth_wrapper/flutter_app_auth_wrapper.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'dart:developer'
;
import
'dart:convert'
;
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
;
final
String
invokerURL
;
Home
({
@required
this
.
mode
,
@required
this
.
host
,
@required
this
.
setHost
,
@required
this
.
authorizeClick
,
@required
this
.
openDashboardClick
,
@required
this
.
buttonsHidden
,
});
final
AppMode
mode
;
final
String
host
;
final
void
Function
(
String
)
setMode
;
final
bool
buttonsHidden
;
final
void
Function
(
String
)
setHost
;
final
void
Function
()
openDashboardClick
;
final
void
Function
()
authorizeClick
;
@override
_HomeState
createState
()
=
>
_HomeState
();
}
class
_HomeState
extends
State
<
Home
>
{
String
_host
=
Config
.
appFlavor
==
Flavor
.
DEVELOPMENT
?
Config
.
HOSTS
[
0
]
:
Config
.
DEFAULT_APP_HOST
;
bool
_hidden
=
true
;
@override
initState
()
{
super
.
initState
();
if
(
widget
.
host
!=
null
)
{
setState
(()
{
_host
=
widget
.
host
;
});
}
showMode
(
widget
.
mode
);
FlutterAppAuthWrapper
.
eventStream
()
.
listen
((
data
)
{
var
token
=
json
.
decode
(
data
.
toString
())[
"access_token"
];
_showAlert
(
token
);
widget
.
setMode
(
""
);
},
onError:
(
error
)
{
log
(
"Err
$error
"
);
widget
.
setMode
(
""
);
});
Timer
(
Duration
(
seconds:
3
),
()
{
setState
(()
{
_hidden
=
false
;
});
}
);
}
Future
<
void
>
_showAlert
(
token
)
{
return
showDialog
<
void
>(
context:
context
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
title:
Text
(
'Authorization success'
),
actions:
<
Widget
>[
FlatButton
(
child:
Text
(
'Go back'
),
onPressed:
()
async
{
Navigator
.
of
(
context
)
.
pop
();
log
(
"Open
${widget.invokerURL}
"
);
try
{
await
launch
(
"
${widget.invokerURL}
?token=
$token
&host=
$_host
"
);
}
catch
(
e
)
{
log
(
"Error launching url
${widget.invokerURL}
"
);
}
},
),
],
);
},
);
}
@override
void
didUpdateWidget
(
Home
oldWidget
)
{
// this method IS called when parent widget passes new "props"
// unlike React, this method IS called _before_ the build
// unlike React, this method ISN'T called after setState()
if
(
widget
.
host
!=
oldWidget
.
host
&&
widget
.
host
!=
null
)
{
setState
(()
{
_host
=
widget
.
host
;
});
}
if
(
widget
.
mode
!=
oldWidget
.
mode
)
{
showMode
(
widget
.
mode
);
}
super
.
didUpdateWidget
(
oldWidget
);
}
showMode
(
mode
)
{
if
(
mode
==
"app"
)
{
openVereign
();
}
else
if
(
mode
==
"oauth"
)
{
startOAuth
();
}
}
openVereign
()
{
FlutterWebBrowser
.
openWebPage
(
url:
_host
,
androidToolbarColor:
Color
(
0xFFd51d32
));
}
startOAuth
()
{
var
params
=
Config
.
getOAuthParams
(
host:
_host
);
FlutterAppAuthWrapper
.
startAuth
(
AuthConfig
(
clientId:
params
[
"clientId"
],
clientSecret:
params
[
"clientSecret"
],
redirectUrl:
params
[
"redirectUrl"
],
state:
"login"
,
prompt:
"consent"
,
endpoint:
AuthEndpoint
(
auth:
params
[
"authEndpoint"
],
token:
params
[
"tokenEndpoint"
]),
scopes:
[
"user_account_status"
,
"user_territory"
,
"user_profile"
],
),
);
}
@override
Widget
build
(
BuildContext
context
)
{
if
(
_h
idden
)
{
if
(
widget
.
buttonsH
idden
)
{
return
Scaffold
();
}
var
children
=
<
Widget
>[
_urlButton
(
context
,
"Open Dashboard"
,
openVereign
),
_urlButton
(
context
,
"Authorize with Vereign"
,
startOAuth
)
_urlButton
(
context
,
"Open Dashboard"
,
widget
.
openDashboardClick
),
];
if
(
widget
.
mode
==
AppMode
.
Authorization
)
{
children
.
add
(
_urlButton
(
context
,
"Authorize with Vereign"
,
widget
.
authorizeClick
));
}
if
(
Config
.
appFlavor
==
Flavor
.
DEVELOPMENT
)
{
children
.
add
(
wrapInContainer
(
DropdownButton
<
String
>(
value:
_
host
,
value:
widget
.
host
,
onChanged:
(
String
newValue
)
async
{
setState
(()
{
_host
=
newValue
;
});
widget
.
setHost
(
newValue
);
final
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
setString
(
"host"
,
newValue
);
},
Loading