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 / blur_image.dart
Created April 19, 2018 04:32
This code snippet include code to add background image and blur that image with some opacity. To learn more go this link: http://slcoderlk.blogspot.com/2018/04/motivational-quote-app-how-to-blur.html
import 'package:flutter/material.dart';
import 'dart:ui';
void main() => runApp(new QuoteApp());
class QuoteApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Motivational Quote App',
@Blasanka
Blasanka / frosted_glass_effect.dart
Created April 20, 2018 19:41
To learn about this code go to: slcoderlk.blogspot.com. This example code for how to add frosted glass effect in flutter, in other word, how to add rectangle shape with opacity. This rectange will scale according to the screen width and height will scale to it's child(responsive to the child or wrap it's content).
import 'package:flutter/material.dart';
import 'dart:ui';
void main() {
runApp(new MaterialApp(
title: 'Motivational Quote App',
home: new QuoteApp(),
));
}
@Blasanka
Blasanka / fonts_flutter.dart
Last active April 21, 2018 11:08
This code demonstrate how to add and use custom fonts in flutter. This is used for flutter and dart tutorial series motivational quote. You can learn about it from slcoderlk.blogspot.com wesite. For this file to work and to add fonts you need to specify your fonts in bottom of the pubspec.yaml file. I have added fonts section as a comment in thi…
/* #add below fonts section to bottom of your pubspec.yaml file. Note: you have to create directory and add fonts. If your directory structure and fonts are different change below lines to yours
fonts:
- family: Gaegu
fonts:
- asset: assets/fonts/Gaegu-Light.ttf
weight: 200
- asset: assets/fonts/Gaegu-Regular.ttf
weight: 500
- family: Tajawal
@Blasanka
Blasanka / navigation_route.dart
Last active May 13, 2018 18:59
This gist demonstrate how to go to another page/route or screen using button press and how to navigate to previous page using named routes(App level routes- using MaterialApp routes property). Refer tutorial here: slcoderlk.blogspot.com
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Navigation and routes',
home: MyApp(),
routes: <String, WidgetBuilder>{
'/SecondPage': (BuildContext context) => new SecondPage(),
},
@Blasanka
Blasanka / peek_pageview_example.dart
Created May 15, 2018 09:45
This simplest example for to demonstrate how to add peek next and previous pages, swipe gesture,page view.
import 'package:flutter/material.dart';
void main() => runApp(LimeApp());
class LimeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lime',
theme: ThemeData(
@Blasanka
Blasanka / page_view_with_fraction.dart
Created May 17, 2018 10:00
Simple example about PageView in flutter with viewPort fraction to get our desired size instead default viewport size: learn more here: slcoderlk.blogspot.com
import 'package:flutter/material.dart';
void main() => runApp(LimeApp());
class LimeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lime',
home: MainPage(),
@Blasanka
Blasanka / name_positional_params.dart
Created May 18, 2018 07:03
Name and positional optional parameters(difference between) in dart
main(List<String> arguments) {
Person person1 = new Person('John', age: 26, address: 'NY');
Person person2 = new Person('Lily', isMale: false, address: 'CA');
print('${person1.name} is ${person1.age} years old and he/she is living in ${person1.address}');
print('${person2.name} is ${person2.age} years old and he/she is living in ${person2.address}');
}
class Person {
@Blasanka
Blasanka / main.dart
Last active May 18, 2018 09:53
Compare simple Dart example with Java
//Dart
main(List<String> arguments) {
List<String> carriers = ['web', 'mobile', 'desktop'];
print('''${carriers.join(', ')
.toUpperCase()} developer''');
}
//Java
// import java.util.Arrays;
// import java.util.List;
@Blasanka
Blasanka / Main.java
Created May 18, 2018 09:39
How to separate elements by comma(without last element) when assign to a String or print using Java.
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.*;
class Main {
public static void main(String[] arg) {
List<String> cities = Arrays.asList("NY", "LA", "Tokyo");
System.out.println(cities.stream().collect(joining(", ")));
}
}
@Blasanka
Blasanka / main.dart
Last active May 18, 2018 09:52
How to separate items in a list by comma(without for last item) using Dart.
//problem
main(List<String> arguments) {
List cities = ['NY', 'LA', 'Tokyo'];
String s = '';
for(var city in cities)
s += '$city, ';
print(s);//NY, LA, Tokyo,
}
// first method