Skip to content

Instantly share code, notes, and snippets.

View tunitowen's full-sized avatar

Tony Owen tunitowen

  • OwenTech Ltd
  • Leeds
View GitHub Profile
import 'package:flutter/material.dart';
import 'dart:math';
const SCALE_FRACTION = 0.7;
const FULL_SCALE = 1.0;
const PAGER_HEIGHT = 200.0;
class ItCrowdPage extends StatefulWidget {
@override
_ItCrowdPageState createState() => _ItCrowdPageState();
@tunitowen
tunitowen / main.dart
Created December 6, 2018 11:31
Multiple Flare Animations - Flutter
import 'package:flutter/material.dart';
import 'package:flare/flare_actor.dart';
const String ANIM_JUST_NIGHT = "just_night";
const String ANIM_NIGHT_TO_DAY = "night_to_day";
const String ANIM_DAY_TO_NIGHT = "day_to_night";
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: FlareActor("assets/heart.flr", alignment:Alignment.center, fit:BoxFit.contain, animation: "heart",),
@tunitowen
tunitowen / GetPeople.kt
Created May 19, 2017 09:09
Room-GettingStarted-GetData
fun registerAllPersonListener() {
MyApp.database?.personDao()?.getAllPeople()
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe { listOfPeople ->
view.personTableUpdated(listOfPeople)
}
}
@tunitowen
tunitowen / AddPerson.kt
Created May 19, 2017 08:29
Room-GettingStarted-AddData
fun addPerson(firstName: String, lastName: String) {
val person = Person(0, firstName, lastName)
Single.fromCallable {
MyApp.database?.personDao()?.insert(person)
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe()
}
@tunitowen
tunitowen / MyApp.kt
Created May 19, 2017 08:13
Room-GettingStarted-AppSetup
class MyApp : Application() {
companion object {
var database: MyDatabase? = null
}
override fun onCreate() {
super.onCreate()
MyApp.database = Room.databaseBuilder(this, MyDatabase::class.java, "we-need-db").build()
}
@tunitowen
tunitowen / MyDatabase.kt
Created May 19, 2017 08:08
Room-GettingStarted-Database
@Database(entities = arrayOf(Person::class), version = 1)
abstract class MyDatabase : RoomDatabase() {
abstract fun personDao(): PersonDao
}
@tunitowen
tunitowen / PersonDao.kt
Created May 19, 2017 08:02
Room-GettingStarted-DAO
@Dao
interface PersonDao {
@Query("SELECT * FROM person")
fun getAllPeople(): Flowable<List<Person>>
@Insert
fun insert(person: Person)
}
@tunitowen
tunitowen / Person.kt
Created May 19, 2017 07:57
Room-GettingStarted-Entity
@Entity
data class Person(
@PrimaryKey(autoGenerate = true)
val uid: Long,
val firstName: String = "",
val lastName: String = ""
)
@tunitowen
tunitowen / build.gradle
Created May 19, 2017 07:54
Room-GettingStarted-Gradle
apply plugin: 'kotlin-kapt'
android {
...
}
dependencies {
...
// Room
compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'