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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
Code Review Best Practice
trishagee
74
20k
The Invisible Side of Design
smashingmag
302
51k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
Speed Design
sergeychernyshev
33
1.5k
Skip the Path - Find Your Career Trail
mkilby
0
58
Embracing the Ebb and Flow
colly
88
5k
Making Projects Easy
brettharned
120
6.6k
Optimizing for Happiness
mojombo
379
71k
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
хࢎפ.