Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Flutter communicate with Native code (iOS, Andr...
Search
word
July 27, 2019
0
130
Flutter communicate with Native code (iOS, Android)
Agenda
- About Flutter
- Flutter Platform Channel
- Demo
- Q & A
word
July 27, 2019
Tweet
Share
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
0
88
The Cult of Friendly URLs
andyhume
79
6.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
390
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
78
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
210
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
0
990
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
160
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
It's Worth the Effort
3n
187
29k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Transcript
'MVUUFSীࢲ/BUJWF J04 "OESPJE ٘৬ాनೞӝ ੋࣻ
*OUSPEVDF അ) Woowahan Bros. / Baemin Market Mobile platform Development
HydaiCapital / Mobile Platform Development SOCAR Mobile Developer / Mobile , Tablet DreamPlus with Hanwha S&C / ZUMO Application Lassoh inc. (Toronto in Canada) / Mobile SNS platform Samsung Mobile Group / ѓ۟द दܻૉ ѐߊ.
"HFOEB "CPVU'MVUUFS 'MVUUFS1MBUGPSN$IBOOFM %FNP 2"
"CPVU'MVUUFS Flutter is Google's mobile UI framework
"CPVU'MVUUFS 'MVUUFSJTBDSPTTQMBUGPSNNPCJMF4%,
Flutter
Fast Beautiful Open Productive Flutter
Fast Beautiful Open Productive Flutter
/BUJWF1FSGPSNBODF
Fast Beautiful Open Productive Flutter
&YQSFTTJWFBOE'MFYJCMF6*
Fast Beautiful Open Productive Flutter
'BTUEFWFMPQNFOU
Fast Beautiful Open Productive Flutter
'SFFBOEPQFOTPVSDF
'MVUUFS)JTUPSZ "OOPVODJOH'MVUUFS $VSSFOU7FSTJPO v1.7 The First Release "OOPVODJOH'MVUUFS3FMFBTF1SFWJFX .": 4&1
%&$ /08
None
2,366 Watch
71,268 Stars
8,432 Forks
421 Contributors
None
None
4UBDL0WFSGMPXUSFOE
4UBDL0WFSGMPXUSFOE
None
None
None
None
None
'MVUUFS4USVDUVSF Native Code Widgets, Rendering Platform Channels Canvas Events Location
Bluetooth Audio Sensors Camera Etc. Service Platform Application
'MVUUFS4USVDUVSF Native Code Widgets, Rendering Platform Channels Canvas Events Location
Bluetooth Audio Sensors Camera Etc. Service Platform Application
"CPVU'MVUUFS1MBUGPSN$IBOOFMT5ZQF .FTTBHF$IBOOFM .FUIPE$IBOOFM &WFOU$IBOOFM
8SJUFDVTUPNQMBUGPSNTQFDJGJDDPEF Use Platform Channels
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
"CPVU1MBUGPSN$IBOOFMT Platform channels are the gateway to accessing platform-specific code
in Flutter.
"CPVU1MBUGPSN$IBOOFMT What do I mean by platform-specific?
"CPVU1MBUGPSN$IBOOFMT Access to device inputs Secure storage (a.k.a. keychain on
iOS)
"CPVU1MBUGPSN$IBOOFMT The Basic building block for creating plugins
"CPVU1MBUGPSN$IBOOFMT MyOS Call Device State Camera Check
8IBUBCPVUQMBUGPSNTQFDJGJDDPEF Options : 1. Use Plugins 2. Write platform-specific code
6TF1MVHJOT
6TF1MVHJOT description: A new Flutter application. dependencies: core: path: ../core
flutter: sdk: flutter flutter_localizations: sdk: flutter xml: ^3.0.0 flutter_redux: ^0.5.0 intl: ^0.15.2 url_launcher: ^3.0.0 path_provider: ^0.4.0 key_value_store_flutter: ^1.0.0 .... ....
"CPVU1MBUGPSN$IBOOFMT MethodChannel class is defined inside the ‘service’ package.
import 'package:flutter/services.dart';
"CPVU1MBUGPSN$IBOOFMT /FFEUPJNQPSUUIFrBTZODsQBDLBHFUPTVQQPSUBTZOD GFBUVSFTJOPVSEBSUDPEFCBTF
import 'dart:async'; Need to import the ‘async’ package to support
async features in our dart codebase.
static const channel = const MethodChannel('tryflutter.github.io/flutter_BabyStep'); To define MethodChannel in
dart we use : Like this… You can name it anything, but the best practice is to name it domain_name/channel_name.
final response = await channel.invokeMethod(message, [optional_arguments]) You can name it
anything, but the best practice is to name it domain_name/channel_name.
Future<Null> _showDialog() async { final response = await channel.invokeMethod("showDialog", ["Called
From Flutter"]); final snackbar = new SnackBar(content: new Text(response)); Scaffold.of(context).showSnackBar(snackbar); }
Future<Null> _openNewPage() async { final response = await channel.invokeMethod("openPage", ["Hi
From Flutter"]); print(response); }
Future<Null> _requestNetwork() async { final response = await channel.invokeMethod( "request",
["https://www.thesportsdb.com/api/v1/json/1/"]); Navigator.push( context, new MaterialPageRoute( builder: (context) => new SecondRoute(data: response), ), ); }
class MainActivity : FlutterActivity() { ... }
val channel = MethodChannel(flutterView, "tryflutter.github.io/ platformchannel”)
channel.setMethodCallHandler { methodCall, result -> val args = methodCall.arguments as
List<*> val param = args.first() as String when (methodCall.method) { "openPage" -> openSecondActivity(param) "showDialog" -> showDialog(param, result) "request" -> callService(param, result) else -> return@setMethodCallHandler } }
private fun openSecondActivity(info: String) { startActivity<SecondActivity>("info" to info) }
private fun showDialog(content: String, channelResult: MethodChannel.Result) { MaterialDialog.Builder(this).title("Native Dialog").theme(Theme.LIGHT) .content(content)
.positiveText("Ok") .negativeText("Cancel") .onPositive { _, _ -> channelResult.success("Ok was clicked") } .onNegative { _, _ -> channelResult.success("Cancel was clicked") } .show() }
private fun callService(url: String, channelResult: MethodChannel.Result) { ... service.getEPLTeams().enqueue(object :
Callback<TeamResponse> { override fun onFailure(call: Call<TeamResponse>?, t: Throwable?) { channelResult.error("FAILURE", "CALL FAILED", t?.localizedMessage) } override fun onResponse(call: Call<TeamResponse>?, response: Response<TeamResponse>?) { channelResult.success(Gson().toJson(response?.body()?.teams)) } }) }
DEMO
None
Q & A
хࢎפ.