Skip to content

Instantly share code, notes, and snippets.

View sawin0's full-sized avatar

Sabin Ranabhat sawin0

View GitHub Profile
@sawin0
sawin0 / main.dart
Created December 11, 2024 07:42
This is a demo project showcasing a user presence system using Flutter and Firebase Realtime Database. It tracks users' online/offline status and updates the presence when the app lifecycle changes or disconnects.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
@sawin0
sawin0 / interest_select_screen.dart
Last active November 18, 2024 06:32
The demo displays a list of hobbies as selectable chips, each paired with an icon. Users can select up to 5 hobbies, and the chips update with a gradient background and white text when selected. If more than 5 hobbies are chosen, a toast message prevents further selection. The hobbies are managed using a custom Interest model that associates eac…
import 'package:flutter/material.dart';
class Interest {
final String name;
final IconData icon;
Interest({required this.name, required this.icon});
}
class InterestSelectScreen extends StatefulWidget {
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
debugInvertOversizedImages = true;
runApp(const MaterialApp(home: RftReaderScreen()));
}
class RftReaderScreen extends StatefulWidget {
const RftReaderScreen({Key? key}) : super(key: key);
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
extension ImageExtension on num {
int cacheSize(BuildContext context) {
return (this * MediaQuery.of(context).devicePixelRatio).round();
}
}
void main() {
@sawin0
sawin0 / main.dart
Created February 20, 2024 06:05
Retro pixel-style loading animations, created with Flutter
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@sawin0
sawin0 / main.dart
Last active February 12, 2024 03:05
Concurrent Asynchronous Operations in Dart: A Guide to Future.wait link: https://www.linkedin.com/pulse/concurrent-asynchronous-operations-dart-guide-sabin-ranabhat-u70nf
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async {
print("Fetching todo data from JSONPlaceholder API using Future.wait method...");
// Create a list of asynchronous tasks to fetch todo data from different users
List<Future<Map<String, dynamic>>> apiCalls = [
fetchTodoData(1),