Created
December 6, 2020 05:04
-
-
Save CoderJava/205d61c9589d19996ffb7122a0eda59b to your computer and use it in GitHub Desktop.
MainActivity.kt sample time zone flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.sample_time_zone_flutter | |
| import io.flutter.embedding.android.FlutterActivity | |
| import io.flutter.embedding.engine.FlutterEngine | |
| import io.flutter.plugin.common.MethodCall | |
| import io.flutter.plugin.common.MethodChannel | |
| import java.util.* | |
| class MainActivity: FlutterActivity(), MethodChannel.MethodCallHandler { | |
| private val channel = "sample_time_zone_flutter_channel" | |
| override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | |
| super.configureFlutterEngine(flutterEngine) | |
| MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler(this) | |
| } | |
| override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { | |
| when (call.method) { | |
| "get_native_time_zone" -> { | |
| val timezone = TimeZone.getDefault() | |
| val timezoneName = timezone.id | |
| val now = Date() | |
| val offsetFromUtc = timezone.getOffset(now.time) / 1000 | |
| val resultMap = mapOf("timezone" to timezoneName, "gmt_offset" to offsetFromUtc) | |
| result.success(resultMap) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment