Skip to content

Instantly share code, notes, and snippets.

View harshpyati's full-sized avatar
🎯
Focusing

Harsh Pyati harshpyati

🎯
Focusing
  • Bengaluru
View GitHub Profile
@harshpyati
harshpyati / index.dart
Created January 16, 2019 14:41
A Gist showing the OOP features of Dart Language
class Person{
String firstName;
int age;
Person(this.firstName,this.age);
printName(){
print(firstName);
}
@harshpyati
harshpyati / oop.dart
Created January 17, 2019 18:32
A program demonstrating a game of Cards written using Dart only using its OOP features.
class Deck{
List<Card> cards = new List<Card>();
Deck(){
var ranks = ['Ace','Two','Three','Four','Five'];
var suits = ['Diamonds','Hearts','Clubs','Spades'];
for(var suit in suits){
for(var rank in ranks){
var card = new Card(rank:rank,
@harshpyati
harshpyati / json.dart
Created January 19, 2019 17:55
A gist describing how data from json can be received in dart language
import 'dart:convert';
class ImageModel{
int id;
String url;
ImageModel(this.id,this.url);
ImageModel.fromJson(parsedJson){
this.id = parsedJson['id'];
this.url = parsedJson['url'];
@harshpyati
harshpyati / handling_future.dart
Created January 19, 2019 18:30
Gist to show the handling of Future while making 'get' http calls in Flutter
import 'dart:async';
main() async{
/*print('About to fetch the data');
get('http:/dkjsbkdsjbdl')
.then((result){
print(result);
});
*/
// Async Await Syntax:
@harshpyati
harshpyati / streams1.dart
Created January 22, 2019 13:21
A gist to show the usage of Streams in Dart.
import 'dart:html';
void main(){
final ButtonElement button = querySelector('button');
// Game: Click the button atleast once in a second otherwise you lose it
button.onClick
.timeout(
new Duration(seconds: 1),
@harshpyati
harshpyati / streams2.dart
Created January 22, 2019 13:22
A gist to show the usage of Streams in Dart
// Model a Chocolate Cake factory using Streams
import 'dart:async';
void main(){
final controller = new StreamController();
/*once the controller is created, it gets 2 attributes
1. Sink - The order taker
2. Factory - Where the processing is done*/
@harshpyati
harshpyati / streams3.dart
Created January 22, 2019 13:50
A gist to show the usage of streams in Dart
import 'dart:html';
import 'dart:async';
void main(){
final InputElement input = querySelector('input');
final DivElement div = querySelector('div');
final validator = new StreamTransformer.fromHandlers(
handleData: (inputValue,sink){
data class UserModel(
val userName : String?,
val userEmailId: String?,
val uuid: String?,
val accountCreatedAt: String?,
)
dependencies{
/* YOUR EXISTING DEPENDENCIES */
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha01"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.core:core-ktx:1.2.0'
}
interface ApiInterface {
@GET("/api/")
suspend fun getPhotos() : Photos
}