Skip to content

Instantly share code, notes, and snippets.

View rutvik110's full-sized avatar
🎵
Humming

Rutvik Tak rutvik110

🎵
Humming
View GitHub Profile
@rutvik110
rutvik110 / future_state_notifier.dart
Created December 17, 2021 10:23
FutureState Notifier Riverpod
import 'package:flutter_riverpod/flutter_riverpod.dart';
//a state notifier that can be used to call a future after an event.
//it will automatically update the state when the future completes
//call [doRequest] to call the future
//pass in [request] to the [doRequest] function or in the constructor
//the [request] in the doRequest function will take precendence over the [request] in the constructor
class FutureStateNotifier<T> extends StateNotifier<AsyncValue<T>> {
FutureStateNotifier({this.request}) : super(AsyncValue<T>.loading());
final Future<T> Function()? request;
@rutvik110
rutvik110 / audio_data_parser.dart
Last active December 13, 2023 01:21
Audio Data parse
import 'dart:convert';
import 'dart:math' as math;
List<double> loadparseJson(String jsonBody) {
final data = jsonDecode(jsonBody);
final List<int> points = List.castFrom(data['data']);
List<int> filteredData = [];
// Change this value to number of audio samples you want.
// Values between 256 and 1024 are good for showing [RectangleWaveform] and [SquigglyWaveform]
@rutvik110
rutvik110 / algolia_data_parser.ts
Created December 20, 2021 06:53
Normal Data to Algolia Format data parser
import { dataProcessor } from "./processors";
export const parseDataToAlgoliaFormat = (snapshot: { [key: string]: any }) => {
let payload: {
[key: string]: boolean | string | number;
} = {
objectID: snapshot.id ?? snapshot.objectID,
path: snapshot.path
};
@rutvik110
rutvik110 / custom_scrollbar.dart
Created December 25, 2021 11:20
Custom ScrollBar
import 'package:flutter/material.dart';
class ScrollBar extends StatefulWidget {
const ScrollBar({
Key? key,
required this.scrollController,
}) : super(key: key);
final ScrollController scrollController;
@rutvik110
rutvik110 / pagination_notifier.dart
Last active December 30, 2021 04:46
Pagination With StateNotifier
import 'package:coves_management/notifiers/pagination/pagination_notifier_state.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
class PaginationNotifier<T> extends StateNotifier<PaginationNotifierState<T>> {
PaginationNotifier({required this.fetchNextItems, required this.hitsPerPage})
: super(const PaginationNotifierState.data([], false)) {
init();
}
@rutvik110
rutvik110 / hero_dialog_route.dart
Last active February 25, 2022 03:18
For Hero Transitions Within Dialogs
import 'package:chaseapp/src/const/other.dart';
import 'package:flutter/material.dart';
// https://github.com/flutter/flutter/issues/10667
// Navigator.push(
// context,
// HeroDialogRoute<void>(
// builder: (context) {
// return Dialog();
// },
// Get Tweet info along with user info if needed by expanding to user
final http.Response responce = await http.get(
Uri.parse(
'https://api.twitter.com/2/tweets?ids=$tweetId&expansions=author_id&user.fields=name,profile_image_url',
),
headers: {
'Authorization': 'Bearer ${Bearer Token}',
},
);
@rutvik110
rutvik110 / databaseprovider_itemsprovider.dart
Last active April 2, 2022 05:45
databaseprovider_itemsprovider
final databaseProvider = Provider<MyDatabase>( (ref) => MyDatabase());
final itemsProvider = FutureProvider<List<Item>>( (ref) async {
return ref.read(databaseProvider).fetchItems() ;
});
@rutvik110
rutvik110 / twitter_embed.dart
Last active May 14, 2022 14:29
Twitter embed with WebView
class TwitterEmbed extends StatefulWidget {
const TwitterEmbed({Key? key}) : super(key: key);
@override
State<TwitterEmbed> createState() => _TwitterEmbedState();
}
class _TwitterEmbedState extends State<TwitterEmbed> {
@override
class TwitterEmbed extends StatefulWidget {
const TwitterEmbed({Key? key}) : super(key: key);
@override
State<TwitterEmbed> createState() => _TwitterEmbedState();
}
class _TwitterEmbedState extends State<TwitterEmbed> {
@override