Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
gmalpha_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
mobile
gmalpha_flutter
Commits
3b157295
Commit
3b157295
authored
Feb 23, 2019
by
艾娇平
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
与原生数据通讯
parent
ef69db8d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
311 additions
and
79 deletions
+311
-79
app_config.dart
lib/app_config.dart
+1
-1
hybrid_stack_manager.dart
lib/hybrid_stack/hybrid_stack_manager.dart
+54
-0
hybrid_stack_manager_plugin.dart
lib/hybrid_stack/hybrid_stack_manager_plugin.dart
+3
-0
router.dart
lib/hybrid_stack/router.dart
+166
-0
router_option.dart
lib/hybrid_stack/router_option.dart
+7
-0
utils.dart
lib/hybrid_stack/utils.dart
+42
-0
main.dart
lib/main.dart
+4
-6
opinion.dart
lib/opinion.dart
+23
-11
ALNetClient.dart
lib/services/ALNetClient.dart
+1
-0
ALServers.dart
lib/services/ALServers.dart
+6
-1
pubspec.lock
pubspec.lock
+3
-59
pubspec.yaml
pubspec.yaml
+1
-1
No files found.
lib/app_config.dart
View file @
3b157295
import
'package:flutter/material.dart'
;
import
'
package:hybrid_stack_manager
/hybrid_stack_manager_plugin.dart'
;
import
'
hybrid_stack
/hybrid_stack_manager_plugin.dart'
;
import
'opinion.dart'
;
...
...
lib/hybrid_stack/hybrid_stack_manager.dart
0 → 100644
View file @
3b157295
import
'dart:async'
;
import
'package:flutter/services.dart'
;
import
'../services/ALNetClient.dart'
;
import
'dart:convert'
;
typedef
Future
<
dynamic
>
MethodHandler
(
MethodCall
call
);
class
HybridStackManagerPlugin
{
static
HybridStackManagerPlugin
hybridStackManagerPlugin
=
new
HybridStackManagerPlugin
.
_internal
();
MethodChannel
_channel
;
MethodHandler
_handler
;
void
setMethodCallHandler
(
MethodHandler
hdler
)
{
_handler
=
hdler
;
_channel
.
setMethodCallHandler
(
_handler
);
}
HybridStackManagerPlugin
.
_internal
()
{
_channel
=
new
MethodChannel
(
'hybrid_stack_manager'
);
}
openUrlFromNative
({
String
url
,
Map
query
,
Map
params
,
bool
animated
})
{
_channel
.
invokeMethod
(
"openUrlFromNative"
,
{
"url"
:
url
??
""
,
"query"
:
(
query
??
{}),
"params"
:
(
params
??
{}),
"animated"
:
animated
??
true
});
}
popCurPage
({
bool
animated
=
true
})
{
_channel
.
invokeMethod
(
"popCurPage"
,
animated
);
}
updateCurFlutterRoute
(
String
curRouteName
)
{
_channel
.
invokeMethod
(
"updateCurFlutterRoute"
,
curRouteName
??
""
);
}
Future
<
Map
>
getMainEntryParams
()
async
{
dynamic
info
=
await
_channel
.
invokeMethod
(
'getMainEntryParams'
);
return
new
Future
.
sync
(()
=>
info
as
Map
);
}
// method 0: GET 1:POST
Future
<
Map
>
callNativeNetWorking
({
String
url
,
HttpMethod
method
,
Map
parameters
})
async
{
dynamic
info
=
_channel
.
invokeMethod
(
'openUrlFromNative'
,
{
"url"
:
url
??
""
,
"method"
:
1
??
0
,
"parameters"
:
(
parameters
??
{}),
});
print
(
'callNativeNetWorking-----
${info.toString()}
'
);
return
new
Future
.
sync
(()
=>
jsonDecode
(
info
.
toString
())
as
Map
);
}
}
lib/hybrid_stack/hybrid_stack_manager_plugin.dart
0 → 100644
View file @
3b157295
export
'hybrid_stack_manager.dart'
;
export
'router_option.dart'
;
export
'router.dart'
;
lib/hybrid_stack/router.dart
0 → 100644
View file @
3b157295
//import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'router_option.dart'
;
import
'hybrid_stack_manager.dart'
;
import
'utils.dart'
;
//import 'dart:io';
//import 'package:image/image.dart' as image;
//import 'dart:math';
typedef
Widget
FlutterWidgetHandler
(
{
RouterOption
routeOption
,
Key
key
});
class
XMaterialPageRoute
<
T
>
extends
MaterialPageRoute
<
T
>
{
final
WidgetBuilder
builder
;
final
bool
animated
;
final
GlobalKey
boundaryKey
;
Duration
get
transitionDuration
{
if
(
animated
==
true
)
return
const
Duration
(
milliseconds:
300
);
return
const
Duration
(
milliseconds:
0
);
}
XMaterialPageRoute
({
this
.
builder
,
this
.
animated
,
this
.
boundaryKey
,
RouteSettings
settings:
const
RouteSettings
(),
})
:
super
(
builder:
builder
,
settings:
settings
);
}
class
Router
extends
Object
{
static
final
Router
singleton
=
new
Router
.
_internal
();
List
<
XMaterialPageRoute
>
flutterRootPageNameLst
=
new
List
();
String
currentPageUrl
=
null
;
FlutterWidgetHandler
routerWidgetHandler
;
GlobalKey
globalKeyForRouter
;
static
Router
sharedInstance
()
{
return
singleton
;
}
Router
.
_internal
(){
setupMethodChannel
();
}
void
setupMethodChannel
(){
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
setMethodCallHandler
((
MethodCall
methodCall
)
async
{
String
method
=
methodCall
.
method
;
if
(
method
==
"openURLFromFlutter"
)
{
Map
args
=
methodCall
.
arguments
;
if
(
args
!=
null
)
{
bool
animated
=
(
args
[
"animated"
]
==
1
);
Router
.
sharedInstance
().
pushPageWithOptionsFromFlutter
(
routeOption:
new
RouterOption
(
url:
args
[
"url"
],
query:
args
[
"query"
],
params:
args
[
"params"
]),
animated:
animated
??
false
);
}
}
else
if
(
method
==
"popToRoot"
)
{
Router
.
sharedInstance
().
popToRoot
();
}
else
if
(
method
==
"popToRouteNamed"
)
{
Router
.
sharedInstance
().
popToRouteNamed
(
methodCall
.
arguments
);
}
else
if
(
method
==
"popRouteNamed"
)
{
Router
.
sharedInstance
().
popRouteNamed
(
methodCall
.
arguments
);
}
});
}
popToRoot
()
{
NavigatorState
navState
=
Navigator
.
of
(
globalKeyForRouter
.
currentContext
);
List
<
Route
<
dynamic
>>
navHistory
=
navState
.
history
;
int
histLen
=
navHistory
.
length
;
for
(
int
i
=
histLen
-
1
;
i
>=
1
;
i
--)
{
Route
route
=
navHistory
.
elementAt
(
i
);
navState
.
removeRoute
(
route
);
}
}
popToRouteNamed
(
String
routeName
)
{
NavigatorState
navState
=
Navigator
.
of
(
globalKeyForRouter
.
currentContext
);
List
<
Route
<
dynamic
>>
navHistory
=
navState
.
history
;
int
histLen
=
navHistory
.
length
;
for
(
int
i
=
histLen
-
1
;
i
>=
1
;
i
--)
{
Route
route
=
navHistory
.
elementAt
(
i
);
if
(!(
route
is
XMaterialPageRoute
)
||
((
route
as
XMaterialPageRoute
).
settings
.
name
!=
routeName
))
{
navState
.
removeRoute
(
route
);
}
if
((
route
is
XMaterialPageRoute
)
&&
((
route
as
XMaterialPageRoute
).
settings
.
name
==
routeName
))
break
;
}
}
popRouteNamed
(
String
routeName
)
{
NavigatorState
navState
=
Navigator
.
of
(
globalKeyForRouter
.
currentContext
);
List
<
Route
<
dynamic
>>
navHistory
=
navState
.
history
;
int
histLen
=
navHistory
.
length
;
for
(
int
i
=
histLen
-
1
;
i
>=
1
;
i
--)
{
Route
route
=
navHistory
.
elementAt
(
i
);
if
((
route
is
XMaterialPageRoute
)
&&
((
route
as
XMaterialPageRoute
).
settings
.
name
==
routeName
))
{
navState
.
removeRoute
(
route
);
break
;
}
}
}
pushPageWithOptionsFromFlutter
({
RouterOption
routeOption
,
bool
animated
})
{
Widget
page
=
Router
.
sharedInstance
().
pageFromOption
(
routeOption:
routeOption
);
if
(
page
!=
null
)
{
GlobalKey
boundaryKey
=
new
GlobalKey
();
XMaterialPageRoute
pageRoute
=
new
XMaterialPageRoute
(
settings:
new
RouteSettings
(
name:
routeOption
.
userInfo
),
animated:
animated
,
boundaryKey:
boundaryKey
,
builder:
(
BuildContext
context
)
{
return
new
RepaintBoundary
(
key:
boundaryKey
,
child:
page
);
});
Navigator
.
of
(
globalKeyForRouter
.
currentContext
).
push
(
pageRoute
);
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
updateCurFlutterRoute
(
routeOption
.
userInfo
);
}
else
{
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
openUrlFromNative
(
url:
routeOption
.
url
,
query:
routeOption
.
query
,
params:
routeOption
.
params
);
}
NavigatorState
navState
=
Navigator
.
of
(
globalKeyForRouter
.
currentContext
);
List
<
Route
<
dynamic
>>
navHistory
=
navState
.
history
;
}
pushPageWithOptionsFromNative
({
RouterOption
routeOption
,
bool
animated
})
{
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
openUrlFromNative
(
url:
routeOption
.
url
,
query:
routeOption
.
query
,
params:
routeOption
.
params
,
animated:
animated
);
}
pageFromOption
({
RouterOption
routeOption
,
Key
key
})
{
try
{
currentPageUrl
=
routeOption
.
url
+
"?"
+
converUrl
(
routeOption
.
query
);
}
catch
(
e
)
{}
routeOption
.
userInfo
=
Utils
.
generateUniquePageName
(
routeOption
.
url
);
if
(
routerWidgetHandler
!=
null
)
return
routerWidgetHandler
(
routeOption:
routeOption
,
key:
key
);
}
static
String
converUrl
(
Map
query
)
{
String
tmpUrl
=
""
;
if
(
query
!=
null
)
{
bool
skipfirst
=
true
;
query
.
forEach
((
key
,
value
)
{
if
(
skipfirst
)
{
skipfirst
=
false
;
}
else
{
tmpUrl
=
tmpUrl
+
"&"
;
}
tmpUrl
=
tmpUrl
+
(
key
+
"="
+
value
.
toString
());
});
}
return
Uri
.
encodeFull
(
tmpUrl
);
}
}
lib/hybrid_stack/router_option.dart
0 → 100644
View file @
3b157295
class
RouterOption
{
String
url
;
Map
query
;
Map
params
;
String
userInfo
;
RouterOption
({
this
.
url
,
this
.
query
,
this
.
params
});
}
lib/hybrid_stack/utils.dart
0 → 100644
View file @
3b157295
import
'dart:async'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'dart:ui'
as
ui
;
import
'package:path_provider/path_provider.dart'
;
import
'package:path/path.dart'
as
path
;
import
'package:flutter/rendering.dart'
;
//import 'package:image/image.dart';
class
Utils
extends
Object
{
static
int
baseId
=
100
;
static
String
pageNameSeperatorToken
=
"_"
;
static
int
generatePrimaryPageId
()
{
return
baseId
++;
}
static
Map
parseUniquePageName
(
String
pageName
)
{
List
components
=
pageName
.
split
(
pageNameSeperatorToken
);
if
(
components
.
length
!=
2
)
return
null
;
return
{
"name"
:
components
[
0
],
"id"
:
components
[
1
]};
}
static
String
generateUniquePageName
(
String
pageName
)
{
return
(
pageName
??
""
)
+
pageNameSeperatorToken
+
generatePrimaryPageId
().
toString
();
}
//
// static Future<Image> getImage(RenderRepaintBoundary object) async {
// ui.Image capture = await object.toImage(pixelRatio: 2.0);
// ByteData data = await capture.toByteData();
// return new Image.fromBytes(capture.width, capture.height, data.buffer.asUint32List());
// }
//
// static Future<File> writeFile(Image outputImage,String fileName) async {
// final Directory directory = await getTemporaryDirectory();
// final File outputFile = new File(path.join(directory.path, fileName));
// List<int> output = encodePng(outputImage);
// return outputFile.writeAsBytes(output);
// }
}
lib/main.dart
View file @
3b157295
import
'package:flutter/material.dart'
;
import
'package:hybrid_stack_manager/router.dart'
;
import
'package:hybrid_stack_manager/hybrid_stack_manager.dart'
;
import
'package:hybrid_stack_manager/router_option.dart'
;
import
'hybrid_stack/hybrid_stack_manager_plugin.dart'
;
import
'app_config.dart'
;
import
'my_app.dart'
;
...
...
@@ -13,10 +11,10 @@ import 'my_app.dart';
void
main
(
)
async
{
AppConfig
.
sharedInstance
();
HybridStackManagerPlugin
plugin
=
HybridStackManagerPlugin
.
hybridStackManagerPlugin
;
Map
args
=
await
plugin
.
getMainEntryParams
();
// HybridStackManagerPlugin plugin =
// HybridStackManagerPlugin.hybridStackManagerPlugin;
runApp
(
new
MyApp
());
Map
args
=
await
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
getMainEntryParams
();
if
(
args
!=
null
&&
args
[
"url"
]
!=
null
)
{
RouterOption
routeOption
=
new
RouterOption
(
url:
args
[
"url"
],
query:
args
[
"query"
],
params:
args
[
"params"
]);
...
...
lib/opinion.dart
View file @
3b157295
...
...
@@ -9,26 +9,23 @@
import
'package:flutter/material.dart'
;
import
'macros/ALColors.dart'
;
import
'macros/ALDevice.dart'
;
import
'
macros/ALCommon
.dart'
;
import
'
package:hybrid_stack_manager
/hybrid_stack_manager_plugin.dart'
;
import
'
services/ALNetClient
.dart'
;
import
'
hybrid_stack
/hybrid_stack_manager_plugin.dart'
;
class
Opinion
extends
StatelessWidget
{
RouterOption
routeOption
;
Opinion
(
RouterOption
option
,
{
Key
key
})
:
super
(
key:
key
)
{
routeOption
=
option
;
}
Widget
build
(
BuildContext
context
)
{
// Map m = Utils.parseUniquePageName(routeOption.userInfo);
return
MaterialApp
(
debugShowCheckedModeBanner:
false
,
title:
'意见与建议'
,
color:
ALColors
.
Color323232
,
theme:
ThemeData
(
splashColor:
Colors
.
white10
,
//水波纹的颜色
splashColor:
Colors
.
white10
,
//水波纹的颜色
),
home:
OpinionPage
(
title:
'意见和建议'
),
);
...
...
@@ -60,7 +57,13 @@ class _OpinionPageState extends State<OpinionPage> {
onTap:
()
{
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
popCurPage
();
}),
title:
new
Text
(
"意见与建议"
,
style:
TextStyle
(
color:
ALColors
.
Color323232
,
fontSize:
16
,
fontWeight:
FontWeight
.
bold
),),
title:
new
Text
(
"意见与建议"
,
style:
TextStyle
(
color:
ALColors
.
Color323232
,
fontSize:
16
,
fontWeight:
FontWeight
.
bold
),
),
),
body:
Container
(
height:
ALDevice
.
height
,
...
...
@@ -96,7 +99,7 @@ class _OpinionPageState extends State<OpinionPage> {
),
Container
(
height:
40
,
margin:
EdgeInsets
.
only
(
left:
30
,
right:
30
,
top:
30
),
margin:
EdgeInsets
.
only
(
left:
30
,
right:
30
,
top:
30
),
padding:
EdgeInsets
.
only
(
bottom:
10
),
decoration:
BoxDecoration
(
border:
Border
(
...
...
@@ -144,12 +147,21 @@ class _OpinionPageState extends State<OpinionPage> {
}
void
confirmClick
(
)
{
// 提交信息 && 回到上一级页面
// MethodHandler hdler = MethodHandler(MethodCall('hj',{'d':'d'}));
// HybridStackManagerPlugin.hybridStackManagerPlugin.setMethodCallHandler(hdler);
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
popCurPage
(
);
// HybridStackManagerPlugin.hybridStackManagerPlugin.openUrlFromNative(url: ''
);
confimSuggestInfo
();
print
(
'confirmClick'
);
}
void
confimSuggestInfo
(
)
{
Map
<
String
,
String
>
parameters
=
{
'phone'
:
'dsdsdsd'
,
'content'
:
'我是一个建议Flutter提交的'
,
'user_id'
:
'123456'
};
HybridStackManagerPlugin
.
hybridStackManagerPlugin
.
callNativeNetWorking
(
url:
ALServers
.
API_ACCOUNT_SUGGESTION
,
method:
HttpMethod
.
HTTPMethodPOTS
,
parameters:
parameters
).
then
((
val
){
print
(
'confimSuggestInfo---
${val}
'
);
});
}
lib/services/ALNetClient.dart
View file @
3b157295
...
...
@@ -14,6 +14,7 @@ import 'dart:io';
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:device_info/device_info.dart'
;
export
'ALServers.dart'
;
class
ALResponse
{
const
ALResponse
(
...
...
lib/services/ALServers.dart
View file @
3b157295
...
...
@@ -8,6 +8,11 @@
import
'../macros/ALDevice.dart'
;
enum
HttpMethod
{
HTTPMethodGET
,
// 0
HTTPMethodPOTS
// 1
}
// API
class
ALServers
{
ALServers
.
_
();
...
...
@@ -22,7 +27,7 @@ class ALServers {
static
const
String
API_ACCOUNT_REGISTER
=
'/api/account/register'
;
// 用户注册
static
const
String
API_ACCOUNT_GETVFC
=
'/api/account/get_vfc'
;
// 获取验证码
static
const
String
API_ACCOUNT_THIRDPART
=
'/api/account/thirdparty_login'
;
// 三方账户登录
static
const
String
API_ACCOUNT_SUGGESTION
=
"/api/v1/suggestion"
;
// 意见与建议
// HOST
}
...
...
pubspec.lock
View file @
3b157295
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
args:
dependency: transitive
description:
name: args
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.1"
async:
dependency: transitive
description:
...
...
@@ -43,13 +29,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
cookie_jar:
dependency: transitive
description:
...
...
@@ -57,13 +36,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.6"
cupertino_icons:
dependency: "direct main"
description:
...
...
@@ -95,20 +67,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
hybrid_stack_manager:
dependency: "direct main"
description:
name: hybrid_stack_manager
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.1"
image:
dependency: transitive
description:
name: image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.7"
json_annotation:
dependency: "direct main"
description:
...
...
@@ -138,19 +96,12 @@ packages:
source: hosted
version: "1.6.2"
path_provider:
dependency:
transitive
dependency:
"direct main"
description:
name: path_provider
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
version: "0.5.0+1"
quiver:
dependency: transitive
description:
...
...
@@ -226,13 +177,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.3.1"
sdks:
dart: ">=2.0.0 <3.0.0"
flutter: ">=0.
3.1
<2.0.0"
flutter: ">=0.
1.4
<2.0.0"
pubspec.yaml
View file @
3b157295
...
...
@@ -23,13 +23,13 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons
:
^0.1.2
hybrid_stack_manager
:
0.1.1
json_annotation
:
^2.0.0
# 网络
dio
:
^2.0.0
# 数据存储
shared_preferences
:
^0.4.2
device_info
:
^0.4.0
path_provider
:
^0.5.0
dev_dependencies
:
...
...
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