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
5c77d18b
Commit
5c77d18b
authored
5 years ago
by
igorwork
Committed by
Markin Igor
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement modal and redirect to invoker.
parent
70ea4576
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Mobile app initial implementation.
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/app.dart
+8
-4
8 additions, 4 deletions
lib/app.dart
lib/screens/home.dart
+70
-25
70 additions, 25 deletions
lib/screens/home.dart
pubspec.lock
+8
-1
8 additions, 1 deletion
pubspec.lock
pubspec.yaml
+1
-0
1 addition, 0 deletions
pubspec.yaml
with
87 additions
and
30 deletions
lib/app.dart
+
8
−
4
View file @
5c77d18b
...
@@ -7,7 +7,6 @@ import 'dart:async';
...
@@ -7,7 +7,6 @@ import 'dart:async';
import
'dart:developer'
;
import
'dart:developer'
;
import
'package:uni_links/uni_links.dart'
;
import
'package:uni_links/uni_links.dart'
;
import
'package:flutter_web_browser/flutter_web_browser.dart'
;
class
App
extends
StatefulWidget
{
class
App
extends
StatefulWidget
{
@override
@override
...
@@ -19,6 +18,9 @@ class _AppState extends State<App> {
...
@@ -19,6 +18,9 @@ class _AppState extends State<App> {
String
_appMode
=
"app"
;
String
_appMode
=
"app"
;
// Url of the app which invoked OAuth
String
_invokerURL
;
@override
@override
initState
()
{
initState
()
{
super
.
initState
();
super
.
initState
();
...
@@ -50,11 +52,12 @@ class _AppState extends State<App> {
...
@@ -50,11 +52,12 @@ class _AppState extends State<App> {
});
});
}
}
updateAppMode
(
uri
)
{
updateAppMode
(
Uri
uri
)
{
log
(
"Uri
${uri
?.toString()
}
"
);
log
(
"Uri
${uri}
"
);
if
(
uri
?.
path
==
"/oauth2"
)
{
if
(
uri
?.
path
==
"/oauth2"
)
{
setState
(()
{
setState
(()
{
_appMode
=
"oauth"
;
_appMode
=
"oauth"
;
_invokerURL
=
uri
.
queryParameters
[
"callbackUrl"
];
});
});
}
else
{
}
else
{
setState
(()
{
setState
(()
{
...
@@ -76,7 +79,8 @@ class _AppState extends State<App> {
...
@@ -76,7 +79,8 @@ class _AppState extends State<App> {
home:
new
Scaffold
(
home:
new
Scaffold
(
appBar:
new
AppBar
(),
appBar:
new
AppBar
(),
body:
Home
(
body:
Home
(
mode:
_appMode
mode:
_appMode
,
invokerURL:
_invokerURL
)
)
),
),
);
);
...
...
This diff is collapsed.
Click to expand it.
lib/screens/home.dart
+
70
−
25
View file @
5c77d18b
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_web_browser/flutter_web_browser.dart'
;
import
'package:flutter_web_browser/flutter_web_browser.dart'
;
import
'package:flutter_app_auth_wrapper/flutter_app_auth_wrapper.dart'
;
import
'package:flutter_app_auth_wrapper/flutter_app_auth_wrapper.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'dart:developer'
;
import
'dart:developer'
;
import
'dart:convert'
;
class
Home
extends
StatefulWidget
{
class
Home
extends
StatefulWidget
{
Home
({
@required
this
.
mode
});
Home
({
@required
this
.
mode
,
@required
this
.
invokerURL
});
final
String
mode
;
final
String
mode
;
final
String
invokerURL
;
@override
@override
_HomeState
createState
()
=
>
_HomeState
();
_HomeState
createState
()
=
>
_HomeState
();
...
@@ -25,6 +28,38 @@ class _HomeState extends State<Home> {
...
@@ -25,6 +28,38 @@ class _HomeState extends State<Home> {
initState
()
{
initState
()
{
super
.
initState
();
super
.
initState
();
showMode
(
widget
.
mode
);
showMode
(
widget
.
mode
);
FlutterAppAuthWrapper
.
eventStream
()
.
listen
((
data
)
{
var
token
=
json
.
decode
(
data
.
toString
())[
"access_token"
];
_showAlert
(
token
);
});
}
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
(
'Try run
${widget.invokerURL}
'
);
if
(
await
canLaunch
(
widget
.
invokerURL
))
{
log
(
'Run
${widget.invokerURL}
'
);
await
launch
(
widget
.
invokerURL
);
}
else
{
log
(
'Could not launch
${widget.invokerURL}
'
);
}
},
),
],
);
},
);
}
}
@override
@override
...
@@ -41,27 +76,36 @@ class _HomeState extends State<Home> {
...
@@ -41,27 +76,36 @@ class _HomeState extends State<Home> {
showMode
(
mode
)
{
showMode
(
mode
)
{
log
(
mode
);
log
(
mode
);
if
(
mode
==
"app"
)
{
if
(
mode
==
"app"
)
{
FlutterWebBrowser
.
openWebPage
(
url:
'https://app.vereign.com'
,
androidToolbarColor:
Colors
.
deepPurple
);
openVereign
(
);
}
else
if
(
mode
==
"oauth"
)
{
}
else
if
(
mode
==
"oauth"
)
{
FlutterAppAuthWrapper
.
startAuth
(
startOAuth
();
AuthConfig
(
clientId:
clientId
,
clientSecret:
clientSecret
,
redirectUrl:
redirectURL
,
state:
"login"
,
prompt:
"consent"
,
endpoint:
AuthEndpoint
(
auth:
authEndpoint
,
token:
tokenEndpoint
),
scopes:
[
"user_account_status"
,
"user_territory"
,
"user_profile"
],
),
);
}
}
}
}
openVereign
()
{
FlutterWebBrowser
.
openWebPage
(
url:
'https://app.vereign.com'
,
androidToolbarColor:
Colors
.
deepPurple
);
}
startOAuth
()
{
FlutterAppAuthWrapper
.
startAuth
(
AuthConfig
(
clientId:
clientId
,
clientSecret:
clientSecret
,
redirectUrl:
redirectURL
,
state:
"login"
,
prompt:
"consent"
,
endpoint:
AuthEndpoint
(
auth:
authEndpoint
,
token:
tokenEndpoint
),
scopes:
[
"user_account_status"
,
"user_territory"
,
"user_profile"
],
),
);
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
return
Scaffold
(
...
@@ -70,20 +114,21 @@ class _HomeState extends State<Home> {
...
@@ -70,20 +114,21 @@ class _HomeState extends State<Home> {
child:
Column
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
children:
_links
.
map
((
link
)
=
>
_urlButton
(
context
,
link
))
.
toList
(),
// children: _links.map((link) => _urlButton(context, link)).toList(),
children:
<
Widget
>[
_urlButton
(
context
,
_links
[
0
],
"Open Vereign"
,
openVereign
),
_urlButton
(
context
,
_links
[
1
],
"Authorize with Vereign"
,
startOAuth
),
]
))));
))));
}
}
Widget
_urlButton
(
BuildContext
context
,
String
url
)
{
Widget
_urlButton
(
BuildContext
context
,
String
url
,
String
title
,
listener
)
{
return
Container
(
return
Container
(
padding:
EdgeInsets
.
all
(
20.0
),
padding:
EdgeInsets
.
all
(
20.0
),
child:
FlatButton
(
child:
FlatButton
(
color:
Theme
.
of
(
context
)
.
primaryColor
,
color:
Theme
.
of
(
context
)
.
primaryColor
,
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
50.0
,
vertical:
15.0
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
50.0
,
vertical:
15.0
),
child:
Text
(
url
),
child:
Text
(
title
),
onPressed:
()
=
>
_handleURLButtonPress
(
context
,
url
),
onPressed:
listener
));
));
}
}
void
_handleURLButtonPress
(
BuildContext
context
,
String
url
)
async
{
FlutterWebBrowser
.
openWebPage
(
url:
url
,
androidToolbarColor:
Colors
.
deepPurple
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pubspec.lock
+
8
−
1
View file @
5c77d18b
...
@@ -170,6 +170,13 @@ packages:
...
@@ -170,6 +170,13 @@ packages:
url: "https://pub.dartlang.org"
url: "https://pub.dartlang.org"
source: hosted
source: hosted
version: "0.2.0"
version: "0.2.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.0"
vector_math:
vector_math:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -179,4 +186,4 @@ packages:
...
@@ -179,4 +186,4 @@ packages:
version: "2.0.8"
version: "2.0.8"
sdks:
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.2.2 <3.0.0"
flutter: ">=
0.1.4
<2.0.0"
flutter: ">=
1.5.0
<2.0.0"
This diff is collapsed.
Click to expand it.
pubspec.yaml
+
1
−
0
View file @
5c77d18b
...
@@ -28,6 +28,7 @@ dependencies:
...
@@ -28,6 +28,7 @@ dependencies:
uni_links
:
0.2.0
uni_links
:
0.2.0
http
:
^0.12.0
http
:
^0.12.0
flutter_app_auth_wrapper
:
^0.1.1+3
flutter_app_auth_wrapper
:
^0.1.1+3
url_launcher
:
5.1.0
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
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