Skip to content

Instantly share code, notes, and snippets.

View smokelaboratory's full-sized avatar
🎵

Sumeet Rukeja smokelaboratory

🎵
View GitHub Profile
class HomeModel extends BaseModel {
Observable<String> apiDataObservable = Observable();
HomeRepo repo = HomeRepo();
void getApiData() async {
apiDataObservable.setValue((await repo.getData(onApiError))?.toString());
}
}
class HomeRepo extends BaseRepo {
Observable<String> loginState = Observable();
dynamic getData(Observable<ApiError> onApiError) async {
return await callApi(() {
return apiService.getData();
}, onApiError, reqCode: 240);
}
}
@smokelaboratory
smokelaboratory / motion_widget_example.dart
Last active March 7, 2020 14:42
Motion Widget Example
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 35, vertical: 50),
child: Motion<Column>(
durationMs: 2500,
Widget getMotionBuilder(MotionElement child, AnimationController animCont,
{bool isExit = false}) {
Animation transAnim;
Widget builder;
switch (child.mode) {
case MotionMode.TRANSLATE_FADE:
transAnim = getTransAnim(child, animCont, isExit);
builder = FadeTransition(
opacity: getOpacAnim(child, animCont, isExit),
@smokelaboratory
smokelaboratory / custom_key.kt
Created March 13, 2020 06:24
JetSec custom key object
val keySpecifications = KeyGenParameterSpec.Builder(
"key_alias",
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
).apply {
setKeySize(256)
setBlockModes(KeyProperties.BLOCK_MODE_GCM)
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
}.build()
val masterKey = MasterKeys.getOrCreate(keySpecifications)
@smokelaboratory
smokelaboratory / enc_file.kt
Created March 13, 2020 06:26
JetSec encrypted file object
encryptedFile = EncryptedFile.Builder(
secretFile,
applicationContext,
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), //master key
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
)
.setKeysetAlias("file_key") //optional
.setKeysetPrefName("secret_file_shared_prefs") //optional
.build()
@smokelaboratory
smokelaboratory / shared_prefs.xml
Created March 16, 2020 04:06
SharedPreferences
<map>
<string name="email">test@gmail.com</string>
</map>
@smokelaboratory
smokelaboratory / biometric_prompt.kt
Created March 16, 2020 04:08
Biometric Prompt method
override fun onAuthenticationSucceeded(result: AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// key is unlocked
}
@smokelaboratory
smokelaboratory / enc_dec_file.kt
Created March 16, 2020 04:09
Encrypt Decrypt file
//save data
encryptedFile.openFileOutput().use { outputstream ->
outputstream.write(et_data.text.toString().toByteArray())
}
//read data
encryptedFile.openFileInput().use { inputstream ->
tv_result.text = String(inputstream.readBytes(), Charsets.UTF_8)
}
@smokelaboratory
smokelaboratory / enc_shared_prefs.kt
Created March 16, 2020 04:11
Encrypt Decrypt SharedPreferences
//to save a value
securedSharedPrefs.edit().putString("name", "android").apply()
//to fetch a value
securedSharedPrefs.getString("name", "")