Skip to content

Instantly share code, notes, and snippets.

View utkarsh-UK's full-sized avatar
🏠
Working from home

Utkarsh utkarsh-UK

🏠
Working from home
View GitHub Profile
@utkarsh-UK
utkarsh-UK / bubble_delayed_animation.dart
Created April 6, 2022 04:47
Animation Example for Delayed staggered animations
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:smart_link/widgets/bubble.dart';
class Intro extends StatefulWidget {
const Intro({Key? key}) : super(key: key);
@override
State<Intro> createState() => _IntroState();
}
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ServiceSearchDelegate extends SearchDelegate<List<String>> {
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.search),
key: ValueKey('search'),
import 'package:dio/dio.dart';
class ElasticRemoteDataSourceImpl {
final Dio dio;
ElasticRemoteDataSourceImpl(this.dio);
Future<List<String>> searchServices(String index, String query) async {
const String ELASTIC_BASE_URL = 'http://localhost:9200/'; //Change this to your publish_address
Future<void> cacheUser(UserModel userModel) async {
try {
final CacheUserModel cacheUser = CacheUserModel(
userModel.email,
userModel.name,
userModel.phone,
userModel.role,
);
//CACHE_BOX_NAME is any string key
import 'package:hive/hive.dart';
part 'cache_user_model.g.dart';
@HiveType(typeId: 1)
class CacheUserModel extends HiveObject {
@HiveField(0)
final String email;
@HiveField(1)
class CacheUserModel {
final String email;
final String name;
final String phone;
final String role;
Future<String> retrieveUserToken() async {
try {
final secureKey = await secureStorage.read(key: SECURE_STORAGE_KEY);
List<int> encryptionKey = (json.decode(secureKey) as List<dynamic>).cast<int>();
final encryptedBox = await hive.openBox(BOX_NAME, encryptionKey: encryptionKey);
String token = encryptedBox.get('token');
encryptedBox.close();
return token;
Future<void> saveUserToken(String token) async {
try {
//BOX_NAME is any string key for you box name.
final secureKey = Hive.generateSecureKey();
final encryptedBox = await Hive.openBox(BOX_NAME, encryptionKey: secureKey);
await encryptedBox.put('token', token);
//SECURE_STORAGE_KEY is any string key.
await secureStorage.write(
key: SECURE_STORAGE_KEY,
Future<void> saveEventToHive() async {
try {
var box = Hive.openBox('first_box');
box.put('event', 'Cache User');
var event = box.get('event')
box.close();
} on Exception catch (e) {
throw CacheException(message: e.toString());
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
runApp(MyApp());
}