Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Laxman Bhattarai erluxman

🏠
Working from home
View GitHub Profile
View functionarguments.dart
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 Apr 15, 2020
Flutter theme switching
View flutterthemeswitch.dart
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 Apr 17, 2020
Fat arrow functions usage
View fastarrowfunctions.dart
void main() {
User()
..firstName = "Laxman"
..lastName = " Bhattarai"
..age = 18
..printUser();
}
class User {
String firstName;
View sliverappbar.dart
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 Apr 24, 2020
How to test exceptions on dart/flutter
View errortesting.dart
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 Apr 25, 2020
Collection addition with Spread operator
View spreadoperatorcollection.dart
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);
View callableclass.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 Apr 27, 2020
Flutter wheel scrollview
View wheelscrollview.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
View arguemnttypes.dart
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);
View aniamtedcontainer.dart
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
main() {
runApp(MainApp());
}
class MainApp extends StatelessWidget {