By, Er Abhimanyu Singh | 18 Mar, 2024
As you know, nowadays the scope of mobile devices has increased a lot and every day new apps are being published on Google Play Store and App Store.
Friends, we currently have mainly two operating systems for mobile. First Android and second iOS. And the number of mobile users is increasing day by day, so if a developer or a company makes an app, then it launches it for both Android and iOS.
Android Apps मुख्यतः JAVA या Kotlin और iOS Apps Swift या Objective C प्रोग्रामिंग language में बनाये जाते हैं। तो अगर हमें Android और iOS दोनों प्लेटफॉर्म के लिए App बनाना है तो हमें दो बार कोड लिखना पड़ेगा। एक बार Android के लिए और एक बार iOS के लिए।
इस Problem का Solution है Flutter। Flutter में आप एक बार कोड लिखकर उसे Android और iOS दोनों में रन करा सकते हैं।
Flutter क्या है?
Flutter मूलरूप से एक Mobile App Development Framework है।
- Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications from a single codebase for any web browser, Android, iOS, Linux, macOS, and Windows. First described in 2015, Flutter was released in May 2017.
- It is a tool that allows you to build native cross-platform apps (Android, iOS, web, desktop) with one programming language and one codebase.
Cross Platform क्या है?
एक ऐसा Codebase जिसे हम किसी भी Platform या Operating Environment में Execute कर सकते हैं, उसे हम Cross Platform कहते हैं।
Flutter बाकी Frameworks से क्यों बेहतर है?
अगर हम इस बात पर ध्यान दें कि Flutter बाकी Frameworks से क्यों बेहतर है, तो आपको बता दें कि Flutter का अपना खुद का Rendering Engine है।
Framework क्या होता है?
Framework एक संरचना है जिस पर आप सॉफ्टवेयर बना सकते हैं। यह एक नींव के रूप में कार्य करता है, जिसकी मदद से आप किसी प्रोजेक्ट को एकदम scratch से शुरू किए बिना बना सकते हैं।
सिंपल भाषा में अगर मैं कहूँ तो यह एक तरीका है जिसमें हम अपने database, logic और visual पार्ट को divide कर देते हैं। MVC की full form Model-View-Controller है, जिसका मतलब है कि database को Model, logic part को Controller और visual पार्ट को View के नाम से जाना जाता है।
मतलब जब हम किसी भी अन्य Framework की सहायता से Cross Platform का Codebase तैयार करते हैं, तब हम जिस Platform पर Codebase को Execute कर रहे हैं, उस Platform के Components की आवश्यकता होती है।
जैसे कि अगर हमने किसी अन्य Framework की सहायता से एक Codebase तैयार किया है और हम उस Codebase को iOS Platform पर Execute कर रहे हैं, तब Codebase को Execute करने के लिए iOS Platform के Components जैसे UI button इत्यादि की जरूरत होती है।
लेकिन Flutter Framework पर Codebase को किसी भी Platform में execute करने पर हमें उस Platform के components की आवश्यकता नहीं होती, क्योंकि Flutter का अपना Rendering Engine है, जो हर एक Pixel को खुद से control करता है।
जिससे Platform के Native Components पर Dependency कम होती है और हम Complex से Complex UI को बेहतर तरीके से design कर सकते हैं। इसीलिए Flutter बाकी Frameworks से बेहतर माना जाता है।
Frameworks are a special type of library that do not have "finished" functions like regular libraries. Frameworks are rather program scaffolding that provides a blueprint but not a finished unit. Therefore, the framework provides the blueprint and basic structure and also shows what the programmer still needs in terms of customization. The framework provides the flow of a software application and tells the developer what it needs and calls developer-provided code as needed. If a library is used, the application calls code from the library.
Dart Programming Introduction
Flutter की इस series में हम Flutter-Dart programming introduction (Hindi) देखेंगे। Dart को Google ने 2011 में introduce किया था। Dart एक open-source, general-purpose, object-oriented programming language है, जिसका syntax लगभग C की तरह ही है। Dart का मुख्य उद्देश्य Web और Mobile के लिए frontend user interface बनाना है।
Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google. It can be used to develop web and mobile apps as well as server and desktop applications. It is an object-oriented, class-based, garbage-collected language with C-style syntax.
Dart Syntax
void main() {
print('Hello World');
}The main() function is a predefined method in Dart. This method acts as the entry point to the application. A Dart script needs the main() method for execution. print() is a predefined function that prints the specified string or value to the standard output, i.e. the terminal.
Output of the above code:
Hello WorldData Types in Dart
Dart एक strongly typed प्रोग्रामिंग language है। इसका मतलब है कि जो भी value हम अपने प्रोग्राम में प्रयोग करते हैं उसका कोई न कोई type होगा, या तो वह string होगा या number। यहाँ हम Dart के कुछ basic data types के बारे में बात करेंगे:
| Data Type | Example | Description |
|---|---|---|
| String | String name = "Ndmeaa Partner"; | यह text को रखता है। इसमें आप single या double quotation mark का प्रयोग कर सकते हैं। |
| num, int, double | int sNo = 23;double price = 501.1; | Dart में दो तरह के numbers होते हैं: 1. Integer 2. Double |
| Boolean | bool isTrue = true;bool isTrue = false; | bool keyword का प्रयोग Boolean value true या false को represent करने में किया जाता है। |
| Object | Animal animal = Animal(); | Dart में सामान्यतः सब कुछ एक object ही होता है, जैसे Integer, String आदि। |
Variables and Functions
Variables
Variables, memory में namespace होते हैं जो values को store करते हैं। किसी variable के नाम को identifier कहते हैं। Dart में variable declare करने के लिए var keyword का प्रयोग किया जाता है।
For example:
var age = 23;यहाँ age एक variable है जिसमें integer value 23 store की गई है। हम इसे int और double से भी declare कर सकते हैं। Dart में Type Inference का feature है, जो var keyword से create करने पर value के type का अनुमान खुद लगा लेता है।
Functions
Function statements का समूह होते हैं जो किसी specific task को perform करते हैं। Functions code के logical blocks में organized होते हैं। किसी function के declaration में function का नाम, return type और parameters शामिल होते हैं।
Dart में function का उदाहरण:
void addNumbers(int a, int b) {
int c = a + b;
print(c);
}
void main() {
addNumbers(2, 7);
}void addNumbers(int a, int b) { ... }: यहaddNumbersनाम का function बनाता है जो दो integer parametersaऔरbलेता है।- Function के अंदर
aऔरbका sum निकालकर variablecमें रखा जाता है और फिरcprint होता है। void main() { ... }: यह main function है जहाँ से program का execution शुरू होता है। यहaddNumbersको 2 और 7 के साथ call करता है।
इस code को run करने पर 2 और 7 का sum, यानी 9, console पर print होगा।
Operators
Dart programming अन्य सभी languages की तरह सभी operators को support करता है, जैसे:
- Arithmetic
- Equality
- Increment or Decrement
- Logical
- Comparison
== और = में फर्क
The double equals sign == is an operator used to check for equality between two values. When you write a == b, you are asking whether a is equal to b. If both have the same value, the expression evaluates to true, otherwise false.
5 == 5evaluates totruebecause 5 is equal to 5.10 == 5evaluates tofalsebecause 10 is not equal to 5.
On the other hand, the single equals sign = is an assignment operator. It is used to assign a value to a variable. For example, x = 5 assigns the value 5 to the variable x.
Decision Making and Loops
Decision Making
Decision-making किसी भी programming language का वह feature है जिसकी सहायता से हम अपने code को किसी special condition के basis पर execute कर सकते हैं।
Dart language निम्न decision-making statements को support करता है:
- if statement
- if-else statement
- switch statement
Example:
void main() {
var age = 21;
if (age > 20) {
print("You are eligible for marriage.");
} else {
print("You are not eligible for marriage.");
}
}var age = 21;: variableagedeclare करता है और उसमें value 21 रखता है।if (age > 20) { ... }: check करता है किageकी value 20 से बड़ी है या नहीं।- अगर
age20 से बड़ी है, तो "You are eligible for marriage." print होता है। - अगर
age20 या उससे कम है, तो "You are not eligible for marriage." print होता है।
यह program run करने पर "You are eligible for marriage." print होगा, क्योंकि age 21 है। अगर आप age की value 20 या उससे कम कर दें, तो "You are not eligible for marriage." print होगा।
Loops
Loops का प्रयोग किसी code के block को बार-बार repeat करने के लिए किया जाता है, और वह code तब तक execute होता है जब तक specific condition पूरी न हो जाए।
Dart language निम्न loop statements को support करता है:
- for
- for..in
- while
- do..while
Example:
void main() {
var names = ["Ndmeaa", "Ndmeaa Partner", "Singh", "Abhimanyu"];
for (var name in names) {
print(name);
}
}Explain:
var names = [...]: चार strings वाली एक listnamesdeclare करता है।for (var name in names) { ... }: listnamesके हर element पर एक-एक करके iterate करता है।- Loop के अंदर
namelist के current element को represent करता है। print(name);: हर नाम को console पर print करता है।
Continue and Break
C programming की तरह Dart programming में भी continue और break keywords का प्रयोग किया जाता है। continue keyword किसी loop के बचे हुए code को skip करके loop के next iteration पर चला जाता है। break keyword किसी भी loop के execution को रोक देता है और उस loop से बाहर आ जाता है।
Example:
void main() {
for (int i = 1; i < 20; i++) {
if (i % 2 == 0) {
continue;
}
print(i);
if (i == 19) {
break;
}
}
}for (int i = 1; i < 20; i++):iको 1 से शुरू करता है और जब तकi20 से कम है, हर बारiको 1 बढ़ाकर loop चलाता है।if (i % 2 == 0) { continue; }: अगरieven number है, तो आगे का code skip करके अगले iteration पर चला जाता है।print(i);: सिर्फ odd numbers print होते हैं।if (i == 19) { break; }: जबi19 हो जाए, तो loop रुक जाता है।
इस code को run करने पर 1 से 19 तक के सभी odd numbers अलग-अलग line में print होंगे।
Final और Const Keyword in Dart
We use the final keyword to restrict the user from changing a value. The final keyword can be applied in many contexts such as variables, classes and methods. The const keyword is used to declare constants. Whenever we declare a value with the const keyword, we cannot change its value later.
हम final keyword का प्रयोग value को बदलने से रोकने के लिए करते हैं। यह variables, classes और methods जैसे कई जगह apply हो सकता है। const keyword का प्रयोग constants declare करने के लिए किया जाता है। जब भी हम किसी value को const से declare करते हैं, तो हम उसकी value को बाद में बदल नहीं सकते।
Example:
void main() {
final num = 200;
const pi = 3.14;
print(num);
print(pi * num);
}void main() { ... }: यह आपके program का entry point है।final num = 200;: variablenumबनाता है और उसमें 200 रखता है।finalका मतलब है कि एक बार value assign होने के बाद उसे बदला नहीं जा सकता।const pi = 3.14;: constantpiबनाता है, जिसकी value लगभग 3.14 है।constकी value कभी बदली नहीं जा सकती।print(num);:numकी value print करता है।print(pi * num);:piऔरnumका गुणनफल print करता है।
यहाँ pi = 3.14 का मतलब है कि variable pi में value 3.14 assign की जा रही है, और pi * num का मतलब है कि pi में रखी value को num में रखी value से multiply किया जा रहा है।
Object-Oriented Programming
Dart is an object-oriented programming language, which means that like all other OOP languages, every value in Dart is an object. A number is also an object in Dart. Dart covers all the concepts of OOP like objects, classes, interfaces, constructors, etc.
Dart एक object-oriented programming language है। इसका मतलब है कि अन्य सभी OOP languages की तरह Dart में भी हर value एक object होती है। Dart में number भी एक object होता है। Dart OOP के सारे concepts को cover करता है, जैसे objects, classes, interfaces, constructors आदि।
Example:
class Dog {
// Property declaration
late String color, type;
// Method creation
String eating() {
return "Dog is eating";
}
String hunting() {
return "Dog is hunting in the jungle.";
}
String resting() {
return "Dog is resting.";
}
}
void main() {
// Object creation
var newDog = Dog();
// Accessing class property
newDog.color = "Black";
newDog.type = "Deshi";
// Output display
print(newDog.color);
print(newDog.type);
print(newDog.hunting());
print(newDog.resting());
print(newDog.eating());
}
Your email address will not be published. Fields marked * are required.