Skip to content

Commit

Permalink
🔨 Code Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-css committed Sep 8, 2023
1 parent 8caec57 commit 6d79ffe
Show file tree
Hide file tree
Showing 27 changed files with 689 additions and 850 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/**/gradle.wrapper/
**/android/.gradle
**/android/captures/
**/android/gradlew
Expand Down Expand Up @@ -76,4 +76,4 @@ ios/.generated/

.idea/instapk.xml
instapk.log*
pubspec.lock
pubspec.lock
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
),
```

*Floating Card*

```dart
CreditCardWidget(
shouldFloat: true,
shouldAddShadow: true,
shouldAddGlare: true,
);
```
> NOTE: Currently the floating card animation is not supported on mobile platform browsers.
4. Adding CreditCardForm

```dart
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.simform.flutter_credit_card'
version '1.0-SNAPSHOT'
version '3.0.7'

buildscript {
ext.kotlin_version = '1.7.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,62 @@ package com.simform.flutter_credit_card

import android.content.Context
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorManager

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel

/** FlutterCreditCardPlugin */
class FlutterCreditCardPlugin: FlutterPlugin {
private lateinit var gyroscopeChannel: EventChannel

private lateinit var methodChannel: MethodChannel

private lateinit var gyroScopeStreamHandler: StreamHandlerImpl

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
setupEventChannels(binding.applicationContext, binding.binaryMessenger)
setupMethodChannel(binding.applicationContext, binding.binaryMessenger)
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
teardownEventChannels()
teardownMethodChannel()
}
private const val GYROSCOPE_CHANNEL_NAME = "com.simform.flutter_credit_card/gyroscope"
private const val METHOD_CHANNEL_NAME = "com.simform.flutter_credit_card"

private fun setupEventChannels(context: Context, messenger: BinaryMessenger) {
val sensorsManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
/** FlutterCreditCardPlugin */
class FlutterCreditCardPlugin : FlutterPlugin {
private lateinit var gyroscopeChannel: EventChannel
private lateinit var methodChannel: MethodChannel
private lateinit var gyroscopeStreamHandler: GyroscopeStreamHandler

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
initEventChannels(binding.applicationContext, binding.binaryMessenger)
initMethodChannel(binding.applicationContext, binding.binaryMessenger)
}

gyroscopeChannel = EventChannel(messenger, GYROSCOPE_CHANNEL_NAME)
gyroScopeStreamHandler = com.simform.flutter_credit_card.StreamHandlerImpl(
sensorsManager,
Sensor.TYPE_GYROSCOPE,
)
gyroscopeChannel.setStreamHandler(gyroScopeStreamHandler)
}
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
disposeChannels()
}

private fun teardownEventChannels() {
gyroscopeChannel.setStreamHandler(null)
gyroScopeStreamHandler.onCancel(null)
}
private fun initEventChannels(context: Context, messenger: BinaryMessenger) {
val sensorsManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager

private fun setupMethodChannel(context: Context, messenger: BinaryMessenger) {
methodChannel = MethodChannel(messenger, METHOD_CHANNEL_NAME)
methodChannel.setMethodCallHandler { call, result ->
if (call.method == "isGyroscopeAvailable") {
val packageManager: PackageManager = context.packageManager
val gyroExists =
packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE)
result.success(gyroExists)
}
gyroscopeChannel = EventChannel(messenger, GYROSCOPE_CHANNEL_NAME)
gyroscopeStreamHandler = GyroscopeStreamHandler(sensorsManager)
gyroscopeChannel.setStreamHandler(gyroscopeStreamHandler)
}
}

private fun teardownMethodChannel() {
methodChannel.setMethodCallHandler(null)
}
private fun initMethodChannel(context: Context, messenger: BinaryMessenger) {
methodChannel = MethodChannel(messenger, METHOD_CHANNEL_NAME)
methodChannel.setMethodCallHandler { call, result ->
when (call.method) {
"isGyroscopeAvailable" -> {
val isAvailable =
context.packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE)
result.success(isAvailable)
}
"dispose" -> {
disposeChannels()
result.success(null)
}
else -> {
result.notImplemented()
}
}
}
}

companion object {
private const val GYROSCOPE_CHANNEL_NAME = "com.simform.flutter_credit_card/gyroscope"
private const val METHOD_CHANNEL_NAME = "com.simform.flutter_credit_card"
private const val DEFAULT_UPDATE_INTERVAL = SensorManager.SENSOR_DELAY_NORMAL
}
private fun disposeChannels() {
methodChannel.setMethodCallHandler(null)
gyroscopeStreamHandler.onCancel(null)
gyroscopeChannel.setStreamHandler(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import android.hardware.SensorManager
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.EventChannel.EventSink

internal class StreamHandlerImpl(
private val sensorManager: SensorManager,
sensorType: Int,
private const val FPS_60 = 16666

internal class GyroscopeStreamHandler(
private val sensorManager: SensorManager,
) : EventChannel.StreamHandler {
private var sensorEventListener: SensorEventListener? = null

private val sensor: Sensor by lazy {
sensorManager.getDefaultSensor(sensorType)
sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE)
}

override fun onListen(arguments: Any?, events: EventSink) {
sensorEventListener = createSensorEventListener(events)
sensorManager.registerListener(sensorEventListener, sensor, 16666)
sensorManager.registerListener(sensorEventListener, sensor, FPS_60)
}

override fun onCancel(arguments: Any?) {
Expand All @@ -31,10 +32,7 @@ internal class StreamHandlerImpl(
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {}

override fun onSensorChanged(event: SensorEvent) {
val sensorValues = DoubleArray(event.values.size)
event.values.forEachIndexed { index, value ->
sensorValues[index] = value.toDouble()
}
val sensorValues = event.values.map { it.toDouble() }.toDoubleArray()
events.success(sensorValues)
}
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion example/.flutter-plugins-dependencies

This file was deleted.

4 changes: 4 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
Expand All @@ -35,6 +36,8 @@
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/**/build/
**/android/**/local.properties

# iOS/XCode related
**/ios/**/*.mode1v3
Expand All @@ -49,6 +52,7 @@
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/Podfile.lock
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
Expand Down
22 changes: 0 additions & 22 deletions example/ios/Podfile.lock

This file was deleted.

26 changes: 0 additions & 26 deletions example/ios/RunnerTests/RunnerTests.swift

This file was deleted.

Loading

0 comments on commit 6d79ffe

Please sign in to comment.