Skip to content

Instantly share code, notes, and snippets.

View mhmadip's full-sized avatar

Mohammad Salim mhmadip

View GitHub Profile
@mhmadip
mhmadip / main.dart
Last active October 11, 2023 11:27
obsidian-eucalyptus-4097
// OOP Principles Example in Dart with Pokemon Context
// 1. Classes and Objects
abstract class Pokemon {
String name;
int level;
Pokemon(this.name, this.level);
// 3. Abstraction (Abstract method representing a move)
@mhmadip
mhmadip / gist:e62a4107fbe60e4e5f1bea4947be8624
Created October 11, 2023 10:11
OOP Principles Example in Dart with Pokemon Context
// OOP Principles Example in Dart with Pokemon Context
// 1. Classes and Objects
abstract class Pokemon {
String name;
int level;
Pokemon(this.name, this.level);
// 3. Abstraction (Abstract method representing a move)
@mhmadip
mhmadip / main.dart
Created February 21, 2023 09:40
This example for OOP2 class, showing how async functions are working on Dart
void main(){
performTasks();
}
void performTasks () async{
task1();
String task2Result= await task2();
task3(task2Result);
}
@mhmadip
mhmadip / main.dart
Created April 15, 2022 14:21
This example shows inheritance in Dart
class Product{
String _name;
num _price;
String _expDate;
Product(this._name,this._price,this._expDate);
void printDetails(){
print('Name: $_name');
print('Price: $_price');
@mhmadip
mhmadip / main.dart
Created April 6, 2022 07:40
Creating Objects using Loop and store them in a list
class Object {
int id = 0;
String name='abc';
Object(this.id);
@override
String toString()=> id.toString() + name;
}
void main() {
@mhmadip
mhmadip / main.dart
Created October 15, 2021 17:23
Explaining OOP in Dart
// classes and objects example
/*
class Car{
int numberOfDoors=5;
void drive(){
print('wheels start turning');
}
}
void main(){
//Enumerated types, often called enumerations or enums,
// are a special kind of class used to represent a fixed number of constant values.
//Declare an enumerated type using the enum keyword:
enum Color { red, green, blue }
//To get a list of all of the values in the enum, use the enum’s values constant.
List<Color> colors = Color.values;
void main() {
//You can use trailing commas when declaring an enumerated type.
//
@mhmadip
mhmadip / main.dart
Last active September 2, 2021 08:27
Sum of odd and even numbers and search for a specific number inside the list
import 'dart:io';
int sumEven(List li) {
int sum = 0;
for (var i in li) {
if (i % 2 == 0) {
sum = sum + i;
}
}
return sum;
}
@mhmadip
mhmadip / main.dart
Created August 23, 2021 07:24
Dart Control Flow Statements
// Chapter 5: Control Flow Statements
void main() {
//if statment
var testList = [2, 4, 8, 16, 32];
print(testList);
if (testList.isNotEmpty) {
print("Emptying List");
testList.clear();
}
print(testList);
@mhmadip
mhmadip / main.dart
Created August 22, 2021 16:54
22.Quiz: Debug Stateful Widgets
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget { @override
Widget build(BuildContext context) {
return MaterialApp( home: MyHomePage(),
); }
}
class MyHomePage extends StatefulWidget { MyHomePage();
@override
createState() => _MyHomePageState();