Skip to content

Instantly share code, notes, and snippets.

View iamEtornam's full-sized avatar
:octocat:
Focusing

Bright Etornam Sunu iamEtornam

:octocat:
Focusing
View GitHub Profile
@iamEtornam
iamEtornam / main.dart
Created October 14, 2024 14:02
Simple animation in Flutter
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@iamEtornam
iamEtornam / main.dart
Last active May 16, 2024 09:47
How to hash a large video file in Dart
import 'dart:io';
import 'dart:convert';
import 'dart:crypto';
import 'package:file/file.dart';
import 'package:stream_transform/stream_transform.dart';
///a function that takes a File object and a chosen hashing algorithm (e.g., SHA-256)
Future<String> hashFile(File file, Digest digest, int chunkSize) async {
final sink = AccumulatorSink<List<int>>();
await file.openRead().pipe(chunkStream(file, chunkSize)).pipe(transform(digest));
@iamEtornam
iamEtornam / core.dart
Created October 8, 2023 22:40
This code sample uses Records or Custom Result class to pass data and exceptions to the UI.
import 'package:example_user_app/result.dart';
import 'package:example_user_app/user.dart';
abstract class Core {
({User? user, Exception? ex}) getUser();
Result getFilterNames({required String name});
}
class CoreImpl implements Core {
User? user;
@iamEtornam
iamEtornam / algo.dart
Created March 27, 2023 18:55
Location address conversion algorithm in dart
///In this implementation, the algorithm divides the map into a grid of 0.05 degrees in width and height, which provides a ///balance between granularity and uniqueness of the address identifier. The algorithm uses a reverse geocoding API to ///retrieve the administrative area, city, and street names for the given location, and includes these components in the ///address identifier along with the grid coordinates. The format of the address identifier is designed to be human-readable ///and consistent with local addressing conventions.
String getAddressFromLocation(double latitude, double longitude) {
// Define the size of the grid in degrees
final double gridWidth = 0.05;
final double gridHeight = 0.05;
// Calculate the grid coordinates for the given latitude and longitude
final int x = ((longitude + 180) / gridWidth).floor();
final int y = ((latitude + 90) / gridHeight).floor();
@iamEtornam
iamEtornam / android_deploy.yml
Created December 12, 2022 23:16
Deploy Flutter apps to PlayStore, AppleStore and Huawei AppGallery. This was generated by ChatGPT
name: Deploy Flutter Appbundle to Play Store
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
import 'package:flutter/material.dart';
class MediaQueryExample extends StatelessWidget {
const MediaQueryExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final size = .of(context).size;
return Scaffold(
appBar: AppBar(title: const Text('MediaQuery Example')),
@iamEtornam
iamEtornam / layoutbuilder_example.dart
Last active October 2, 2022 11:23
How to use MediaQuery in Flutter to determine responsiveness
import 'package:flutter/material.dart';
class LayoutBuilderExample extends StatelessWidget {
const LayoutBuilderExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('LayoutBuilder Example')),
body: LayoutBuilder(builder: (context, constraints) {
@iamEtornam
iamEtornam / release_asset.yml
Created March 20, 2022 15:00
Github actions for Flutter app
name: Release assets
on:
release:
types: [published]
workflow_dispatch:
jobs:
release-asset:
name: Release (foss)
@iamEtornam
iamEtornam / auth_controller.dart
Last active February 15, 2022 15:38
a flutter controller with firebase auth, storage, firestore usage
```dart
import 'package:firebase_auth/firebase_auth.dart';
abstract class AuthController {
Future<bool> loginUser(String email, String password);
Future<bool> logout();
}
class AuthControllerImpl implements AuthController {
@iamEtornam
iamEtornam / firebase_file_uploader.dart
Last active January 29, 2022 11:24
A simple code snippet to upload any file type to firebase storage
```dart
import 'package:mime/mime.dart'; //add mime to pubspec.yaml
import 'package:uuid/uuid.dart'; //add uuid to pubspec.yaml
import 'package:firebase_storage/firebase_storage.dart'; //add firebase storage to pubspec.yaml
import 'package:path/path.dart'; //add path to pubspec.yaml
final firebaseStorage = FirebaseStorage.instance;
Future uploadFile({required File file}) async {
const uuid = Uuid();