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
Measuring & Analyzing Core Web Vitals
bluesmoon
7
520
Unsuck your backbone
ammeep
671
58k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Gamification - CAS2011
davidbonilla
81
5.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Agile that works and the tools we love
rasmusluckow
329
21k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Become a Pro
speakerdeck
PRO
29
5.4k
Speed Design
sergeychernyshev
32
1k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
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
хࢎפ.