0% found this document useful (0 votes)
2 views14 pages

Mobile

The document provides an overview of native and cross-platform mobile applications, detailing their definitions, languages, tools, pros, and cons. It also includes a tutorial on the Dart programming language, covering features such as string interpolation, nullable variables, null-aware operators, collection literals, and function parameters. Additionally, it demonstrates Dart's syntax and methods through examples and code snippets.

Uploaded by

Marwan Sherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

Mobile

The document provides an overview of native and cross-platform mobile applications, detailing their definitions, languages, tools, pros, and cons. It also includes a tutorial on the Dart programming language, covering features such as string interpolation, nullable variables, null-aware operators, collection literals, and function parameters. Additionally, it demonstrates Dart's syntax and methods through examples and code snippets.

Uploaded by

Marwan Sherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

Native Mobile Applications


Definition: Apps built for a specific OS (Android or iOS).
Languages Used:
Android: Java, Kotlin
iOS: Objective-C, Swift
Examples: Google Maps, WhatsApp, Pinterest
Tools:
Android: Android Studio, IntelliJ IDEA
iOS: Xcode, AppCode
Pros:
High performance
Better security
Better user experience (UX)
Full access to device features
Fewer bugs
Cons:
High development cost (separate teams for each platform)
Long development time
No code reusability

2. Cross-Platform Mobile Applications

Definition: Apps built using one codebase for multiple platforms (Android & iOS).
Frameworks:
React Native (JavaScript)
Flutter (Dart)
.NET MAUI/Xamarin (C#)
Examples:
React Native: Instagram, Skype .. etc
Flutter: Google Ads, eBay Motors, New York Times
Xamarin: The World Bank, Alaska Airlines
Pros:
Lower cost (one development team)
Faster development (code reusability)
Easier maintenance (single codebase)
Cons:
Larger app size
Harder to integrate some hardware features
Lower performance than native apps
Delayed support for new platform features
The Dart language is designed to be easy to learn for coders coming from
other languages, but it has a few unique features. This tutorial walks you through
the most important of these language features.

String interpolation

To put the value of an expression inside a


string, use ${expression}.

'${3 + 2}' '5'

'${"word".toUpperCase()}' 'WORD'

'$myObject' The value of myObject.toString()

class Person {

String name;
String email;
String phone;

Person(this.name, this.email , this.phone);


}

void main() {
Person p = Person( "Nour Ahmed" , "[email protected]" , "01011111111");
print(p); //output: Instance of 'Person'
}

******************
class Person {

String name;
String email;
String phone;

Person(this.name, this.email , this.phone);


}

@override
String toString() {

return 'Person( name: $name , email: $email , phone: $phone )';


}
}

void main() {
Person p = Person( "Nour Ahmed" , "[email protected]" , "01011111111");
print(p);

output :Person( name: Nour Ahmed , email: [email protected] , phone: 01011111111)

}
______________________________________________

String stringify(int x, int y) {


return '$x $y';
}
}

stringify(10 , 10 )
//output '10 10'

Nullable variables
Dart enforces sound null safety. This means values
can't be null unless you say they can be. In other
words, types default to non-nullable.

When creating a variable, add ? to the type to indicate


that the variable can be null

int a = null; // INVALID.

int? a = null; // Valid.

int? a; // The initial value of a is null.

__________Example_______________

void main() {
String ? name = 'Nour Ahmed';
String ? address;
try {
if (name == 'Nour Ahmed' && address == null)
{
// verify that "name" is nullable
ll
name = null;
print('Success!');
}
else {
print('Not quite right, try again!');
}
}
catch (e) {
print('Exception: ${e.runtimeType}');
}
}

Null-aware operators

Dart offers some handy operators for dealing with values that might be null.
One is the ??= assignment operator, which assigns a value to a variable only if
that variable is currently null:

______ Ex 1________
int ? a ; // = null
a ??= 3;
print(a); // <-- Prints 3.

a ??= 5;
print(a); // <-- Still prints 3.

_______ Ex2 ____________

print(1 ?? 3) // <-- Prints 1.

print(null ?? 12) // <-- Prints 12.


Conditional property access
To guard access to a property or method of an object that might be
null, put a question mark (?) before the dot (.)

myObject?.someProperty;

The preceding code is equivalent to the following:


if (myObject != null)

{ return myObject.someProperty ; }

else{ return null ; }

Collection literals

Dart has built-in support for lists, maps, and


sets

final aListOfStrings = ['one', 'two', 'three'];

final aSetOfStrings = {'one', 'two', 'three'};

final aMapOfStringsToInts = {'one': 1, 'two': 2, 'three': 3};

Or you can specify the type


final aListOfInts = <int>[];

final aSetOfString = <string>{};

final aMapOfIntToDouble = <int, double>{};


Method Description

any() Checks if any element


satisfies the condition.

every() Checks if all elements


satisfy the condition.

where() Returns a list of elements


that satisfy the condition.

firstWhere() Returns the first element


that satisfies the condition.

lastWhere() Returns the last element


that satisfies the condition.

contains() Checks if the list contains a


specific element.

indexWhere() Returns the index of the first


element that satisfies the
condition.

lastIndexWhere() Returns the index of the last


element that satisfies the
condition.
Arrow syntax
It’s ideal when your function consists of a single
expression.

without using Arrow syntax


bool hasEmpty = aListOfStrings.any((s) {

return s.isEmpty;

});

with using Arrow syntax

bool hasEmpty = aListOfStrings.any((s) => s.isEmpty);

Cascade
class Item {

int id;

double price;

Item(this.id, this.price);
void discount(double discount) {

price -= price * (discount / 100);

@override

String toString() {

return "Item('ID : $id, Price: ${price})";

void receipt() {

print('Item : $id, Price: ${price}');

void main() {

Item item= Item (1, 1000);

// Before the discount

print (item );

// After the discount

item..discount(10) ..receipt();
}

output

Item('ID : 1, Price: 1000)

Item : 1, Price: 900

Optional positional parameters

Dart has two kinds of function parameters:


positional and named.

1- Positional parameters

int sumUp(int a, int b, int c) {


return a + b + c;
}
// ···
int total = sumUp(1, 2, 3);
With Dart, you can make these positional
parameters optional by wrapping them in
brackets

int sumUpToThree(int a, [int? b, int? c, ]) {

int sum = a;

if (b != null) sum += b;

if (c != null) sum += c;

return sum;

// ···

int total = sumUpToThree(1, 2);

int otherTotal = sumUpToThree(1, 2, 3,);

another default value

int sumUpToFive(int a, [int b = 2, int c = 3, int d = 4, int e =


5]) {
// ···

void main() {

int newTotal = sumUpToFive(1);

print(newTotal); // <-- prints 15

2- Named parameters

Using a curly brace syntax at the end of the


parameter list, you can define parameters that
have names.

void printName( String firstName, String lastName,


{String? middleName}) {

print('$firstName ${middleName ?? ''} $lastName');

void main() {
printName('Dash', 'Dartisan');

printName('Nour', 'Aboubaker', middleName: 'Ahmed');

// Named arguments can be placed anywhere in the


argument list

printName('Nour ', middleName: 'Ahmed ', 'Aboubaker');

You might also like