Skip to content

Instantly share code, notes, and snippets.

@this-is-richard
this-is-richard / recursive-object.component.ts
Created August 30, 2018 09:01
Angular 6 pretty print json on html (can be array / object)
import { Component } from '@angular/core';
@Component({
selector: 'app-recursive-object',
template: `
<span *ngIf="isArray(items)">[</span>
<span *ngIf="!isArray(items)">{{ '{' }}</span>
<div *ngFor="let key of objectKeys(items)" class="ml-3">
<span *ngIf="!isArray(items)">{{ key }}: </span>
@this-is-richard
this-is-richard / hkid-validation.js
Created September 24, 2018 04:31
hkid-validation.js
function charToNumber(char) {
if (char === ' ') {
return 58
} else if (!isNaN(char)) {
return parseInt(char)
} else {
return char.toUpperCase().charCodeAt(0) - 55;
}
}
@this-is-richard
this-is-richard / main.dart
Last active March 10, 2019 15:22
Everything starts from colours
// imports and the main() function above
class WhatsAppClone extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'WhatsApp',
theme: ThemeData(
primaryColor: Color(0xff075e54),
indicatorColor: Colors.white,
primaryColorDark: Color(0xFF128C7E),
@this-is-richard
this-is-richard / home.dart
Last active March 11, 2019 03:56
The WhatsApp tabview
// above are the imports
class Home extends StatelessWidget {
final _tabs = <Widget>[
Tab(icon: Icon(Icons.camera_alt)), Tab(text: 'CHATS'),
Tab(text: 'STATUS'), Tab(text: 'CALLS'),
];
@override
Widget build(BuildContext context) {
return DefaultTabController(
// Inside the build() method of our ChatRoom() widget
return Scaffold(
backgroundColor: Color(0xFFECE5DD),
appBar: AppBar(
title: , // <-- we will do the trick here
actions: <Widget>[
IconButton(
icon: Icon(Icons.videocam),
onPressed: () {},
),
class ChatRoom extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFECE5DD),
appBar: AppBar(
// leading: CircleAvatar(...), <-- remove this avatar
title: Row(
children: <Widget>[
// Inside the build() method of our ChatRoom() widget
return Scaffold(
backgroundColor: Color(0xFFECE5DD),
appBar: AppBar(
title: SizedBox(
width: double.infinity,
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
class ChatRoom extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFECE5DD),
appBar: AppBar(...), // Title text, action buttons on the right
body: Column(
children: <Widget>[
Expanded(
child: ListView(...), // chat threads
class ChatList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
// itemCount: , <-- Normally we put the data array's length.
itemBuilder: (context, index) {
return ListTile(
title: Text('Contact $index'),
);
},
import 'package:flutter/material.dart';
class ChatList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(itemBuilder: (context, index) {
return ListTile(
title: Text('Contact $index'),
//// onTap START ////
onTap: () {