Skip to content

Instantly share code, notes, and snippets.

View erluxman's full-sized avatar
🏠
Working from home

Laxman Bhattarai erluxman

🏠
Working from home
View GitHub Profile
@erluxman
erluxman / callableclass.dart
Created April 26, 2020 02:31
Callable class dart
void main() {
var member = CallableClass();
member("Flutter");
}
class CallableClass{
// Define method with name `call` which will be called.
call(String name){
print("Name is $name");
}
@erluxman
erluxman / spreadoperatorcollection.dart
Created April 25, 2020 01:32
Collection addition with Spread operator
void main() {
var numbers = [1, 2, 3];
var names = ["Smith", "Laxman"];
List<int> nullList;
List<int> getLostNumbers() => null;
//This is long way
print("\n\n\nLong Way");
var list = List();
list.addAll(numbers);
@erluxman
erluxman / errortesting.dart
Created April 24, 2020 03:00
How to test exceptions on dart/flutter
void main() {
group("Exception/Error testing", () {
test("test method that throws errors", () {
expect(_testError(fails: false), false);
expect(() => _testError(fails: true), throwsA(isA<FooError>()));
});
});
}
@erluxman
erluxman / sliverappbar.dart
Created April 21, 2020 03:00
SliverAppbar
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(body: SliverAppBarDemo()),
@erluxman
erluxman / fastarrowfunctions.dart
Created April 17, 2020 02:52
Fat arrow functions usage
void main() {
User()
..firstName = "Laxman"
..lastName = " Bhattarai"
..age = 18
..printUser();
}
class User {
String firstName;
@erluxman
erluxman / flutterthemeswitch.dart
Created April 15, 2020 03:13
Flutter theme switching
import 'package:flutter/material.dart';
void main() => runApp(ProductiveApp());
class ProductiveApp extends StatefulWidget {
@override
_ProductiveAppState createState() => _ProductiveAppState();
}
class _ProductiveAppState extends State<ProductiveApp> {
@erluxman
erluxman / functionarguments.dart
Last active April 13, 2020 15:02
FunctionnArguments
void main() {
f2(f1, 3);
f2(f1, 4);
f2(f1, 7);
f2(f1, 9);
}
f1(int evenOrOdd) {
print("$evenOrOdd is ${evenOrOdd % 2 == 0 ? "Even" : "Odd"}");
}
@erluxman
erluxman / FunctionAsParameter
Last active April 13, 2020 15:00
dart functions as parameter
void main() {
function2(function1, 3);
function2(function1, 4);
function2(function1, 7);
function2(function1, 9);
}
function1(int evenOrOdd) {
print("$evenOrOdd is ${evenOrOdd % 2 == 0 ? "Even" : "Odd"}");
}
@erluxman
erluxman / listviewseparated.dart
Created April 12, 2020 01:49
ListViewbuilder with Separator
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@erluxman
erluxman / SpacerDemo.dart
Last active April 11, 2020 01:49
Demo of spacer widget
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(