Skip to content

Instantly share code, notes, and snippets.

View Blasanka's full-sized avatar
🚀
Flutter dev

B Liyanage Asanka Blasanka

🚀
Flutter dev
View GitHub Profile
@Blasanka
Blasanka / main.dart
Last active November 2, 2019 17:30
How to compare int list with object list and add to new list(Will help to find selected users based on user ids and other info) using Dart's where()
void main() {
List ids = ['1234', '3455', '2330', '1111'];
List users = [{"id": '1234', "name": "username"}, {"id": '3455', "name": "username"}];
List selectedUsers = users.map((user) {
if(ids.contains(user["id"])) return user;
return null;
}).toList();
//Above line can replace with where(), as
List selects = users.where((u) => ids.contains(u["id"])); // where() accept method that returns boolean based on provided condition and the if the condition is true, that element will add to the new list.
print(selectedUsers);
@Blasanka
Blasanka / main.dart
Created May 15, 2019 17:18
Circular notched FloatingActionButton with BottomNavigationBar
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Flutter GTranslate Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyApp(),
));
Material(
shape: CircleBorder(),
color: kinderm8Theme.Colors.appdarkcolour,
child: Container(
width: 60.0,
height: 60.0,
padding: const EdgeInsets.all(8.0),
child: decideDeleteOrSendActionWidget(),
)),
@Blasanka
Blasanka / main.dart
Created May 7, 2019 11:19
This is a Flutter UI demo. For more details goto slcoderlk.blogspot.com. Note: I have done everything in one file, so that you guys can copy paste to your main.dart and use. But you can separate to files easily because I have done this function wise.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@Blasanka
Blasanka / pubspec.yaml
Last active January 27, 2019 20:43
This is a complete code example for beautiful user profile material ui design with Flutter and Dart. Here is blog post and video for this: https://slcoderlk.blogspot.com/2019/01/beautiful-user-profile-material-ui-with.html
name: mysqltest
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
@Blasanka
Blasanka / flutter_gridview.dart
Last active June 2, 2022 05:10
Flutter Staggered GridView for flexible different height card or content instead gridview in flutter. Read my Stack Overflow answer here: https://stackoverflow.com/questions/49781657/adjust-gridview-child-height-according-to-the-dynamic-content-in-flutter/54059209#54059209
import 'package:flutter/material.dart';
//this is what you need to have for flexible grid
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
//below two imports for fetching data from somewhere on the internet
import 'dart:convert';
import 'package:http/http.dart' as http;
//boilerplate that you use everywhere
@Blasanka
Blasanka / emojis.json
Created October 31, 2018 14:46 — forked from oliveratgithub/emojis.json
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family_mothers_two_girls", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128103;", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family_mothers_children", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128103;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family_mothers_two_boys", "shortname": "", "unicode": "", "html": "&#128105;&zwj;&#128105;&zwj;&#128102;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family_two_girls", "shortname": "", "unicode": "", "html": "&#128104;&zwj;&#128105;&zwj;&#128103;&zwj;&#128103;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👧‍👦", "name": "family_children", "shortname": "", "unicode": "", "html": "&#128104;&zwj;&#128105;&zwj;&#128103;&zwj;&#128102;", "category": "p", "order": ""},
{"emoji": "👨‍👩‍👦‍👦", "name": "family_two_boys", "shortname": "", "unicode": "", "html": "&#128104;&zw
@Blasanka
Blasanka / firebase-javascript-simple-form.html
Last active August 29, 2018 14:59
This code snippet explain, how to add simple html inputs values to firebase realtime database.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Hello Dude</h1>
@Blasanka
Blasanka / main.dart
Created July 8, 2018 13:12
replace items in a list or update items in a list in dart
//The easy way:
void main() {
var collection=[0, 1, 2];
for(int i = 0; i < collection.length; i++) {
collection[i] += 1;
}
print(collection);
}
@Blasanka
Blasanka / main.dart
Created July 2, 2018 06:03
This is a very long text used to demonstrate how to wrap text inside a Column or Row widget. And also to show how to add another row of icon button next to these text widget without going overflow and be center of text widget in main axis
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'LogIn n SignUp',
theme: ThemeData(