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
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
How GitHub (no longer) Works
holman
315
140k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.2k
Balancing Empowerment & Direction
lara
3
630
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building Applications with DynamoDB
mza
96
6.6k
Building an army of robots
kneath
306
46k
Agile that works and the tools we love
rasmusluckow
330
21k
Done Done
chrislema
185
16k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
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
хࢎפ.