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 / str_manipulation.dart
Created January 16, 2020 06:23
Different ways to replace string
void main() {
String str = "one.two";
print(str.replaceAll(".two", ""));
// or
print(str.split(".").first);// split() will split from . and gives new List with separated elements.
// or
@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 / background_image.dart
Last active September 16, 2020 10:25
Lear more in slcoderlk.blogspot.com This code demonstrate how to add background image to your flutter app. Also you have to add assets section and specify images in flutter section. https://gist.github.com/Blasanka/3dece37b5b28f5bbf099581ae4cbe8aa
import 'package:flutter/material.dart';
void main() => runApp(new QuoteApp());
class QuoteApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Motivational Quote App',
home: new Scaffold(
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
@Blasanka
Blasanka / horizontal_list_alignment.dart
Created May 4, 2020 13:15
Center items as long as there are only few items on the list which does not exceed available screen size and when it does and scrolling is available left align all items in the list view.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@Blasanka
Blasanka / nested_list_iteration.dart
Last active May 1, 2020 16:05
This is a example to interate over nested list and access map inside it and render values on it.
import 'dart:convert';
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
@Blasanka
Blasanka / replash_hash_tag_url.dart
Created January 23, 2020 02:14
This is how you can replace hash tag with forward slashes in url
void main() {
String text = "Test #/first1hashtag test #/second2hashtag test.";
RegExp exp = new RegExp(r"\B#\/");
exp.allMatches(text).forEach((match){
print(match.group(0));
text = text.replaceAll(match.group(0), "");
});
print(text);
String text2 = "Test #/first1hashtag test #/second2hashtag test.";
void main() {
var locations = {
{
'country': 'Egypt',
'city': 'Cairo',
'Latitude': 30.033333,
'Longitude': 31.233334,
'utcOffset': 2
},
{
@Blasanka
Blasanka / add_map_to_complex_map.dart
Created January 15, 2020 16:18
Here is how to add complex map to complex map.
void main() {
Map parentMap = {
'childOne': {
'grandSon': {
'grandGrandChild': {
'childOne': 'John',
'childTwo': 'Ron'
}
},
'grandDaughter': {
@Blasanka
Blasanka / main.dart
Last active January 15, 2020 11:30
How to add values to a Map and finally that map to a list (Dart).
void main() {
List<Map> _pecasList = [];
List<String> alphas = ["a", "b", "c"];
Map<String, dynamic> newPecas = Map();
for (String c in alphas) {
if (c.isEmpty || c.trimLeft() == "") {
print("Campo Vazio");
} else {