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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / wheelscrollview.dart
Created April 27, 2020 02:33
Flutter wheel scrollview
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@erluxman
erluxman / rectangularnotch.dart
Created April 28, 2020 02:28
Rectangular notched Fab
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@erluxman
erluxman / arguemnttypes.dart
Created May 1, 2020 08:35
Arguement types
void main() {
normalFunction("Laxman", "Bhattarai", 26, 65);
optionalFunction("Laxman", "Bhattarai");
optionalFunction("Laxman", "Bhattarai", age: 26);
optionalFunction("Laxman", "Bhattarai", weight: 65);
optionalFunction("Laxman", "Bhattarai", weight: 65, age: 26);
positionalFunction("Laxman", "Bhattarai");
positionalFunction("Laxman", "Bhattarai", 26);