Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created February 18, 2021 08:57
Show Gist options
  • Save doyle-flutter/4ba8eed5f96adadee533c2c805425b21 to your computer and use it in GitHub Desktop.
Save doyle-flutter/4ba8eed5f96adadee533c2c805425b21 to your computer and use it in GitHub Desktop.
#06 백그라운드 - 플러터
// ... import 생략
class IntentService extends StatefulWidget {
@override
_IntentServiceState createState() => _IntentServiceState();
}
class _IntentServiceState extends State<IntentService> {
String data;
MethodChannel dataChannel;
@override
void initState() {
dataChannel = new MethodChannel("app.james.cam/backdata")
..setMethodCallHandler((call) {
print(call.method);
print(call.arguments.toString());
if (call.method == "data") {
if(!mounted) return;
setState(() {
this.data = call.arguments;
});
}
return;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(this.data ?? "IntentService with Flutter"),),
body: Center(
child: TextButton(
child: Text("Play"),
onPressed: () async{
const String _method = "intentservicestart";
const String _channelName = "app.james.cam/intentservice";
MethodChannel channel = new MethodChannel(_channelName);
await channel.invokeMethod<void>(_method);
return;
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment