Posts

Showing posts from July, 2020

Dart: mixins

Image
  Mixins in Dart The mixin keyword was introduced in dart 2.1 and it is analogous to abstract class in some ways and different from it in other way. Like abstract class , you can declare abstract methods in mixins and it cannot be instantiated. But unlike abstract , you can’t extend a mixin. You can either use the keyword mixin , abstract class or a normal class as a mixin. Let’s take a look at how we can solve the above problem with mixins. Always keep in mind that mixin is not multiple inheritance instead they are just a way to reuse our code from a class in multiple hierarchies without needing to extend them. Its like being able to use other people assets without being their children When mixing classes, the classes used as mixins are not parallel but instead on top of the class using it. This is the reason why methods do not conflict with one another, allowing us to use codes from multiple classes without having to deal with the vulnerabilities of multiple inheritance.

Flutter: Layouts

Image
  Layouts in Flutter The core of Flutter’s layout mechanism is widgets. In Flutter, almost everything is a widget—even layout models are widgets. The images, icons, and text that you see in a Flutter app are all widgets. But things you don’t see are also widgets, such as the rows, columns, and grids that arrange, constrain, and align the visible widgets. You create a layout by composing widgets to build more complex widgets. For example, the first screenshot below shows 3 icons with a label under each one:   Lay out a widget How do you layout a single widget in Flutter? This section shows you how to create and display a simple widget. It also shows the entire code for a simple Hello World app. In Flutter, it takes only a few steps to put text, an icon, or an image on the screen. 1. Select a layout widget Choose from a variety of layout widgets based on how you want to align or constrain the visible widget, as these characteristics are typically passed on to the contained w

Flutter: Everything is a widget

Image
  Widgets The core concept of the Flutter framework is In Flutter, Everything is a widget . Widgets are basically user interface components used to create the user interface of the application. In Flutter , the application is itself a widget. The application is the top- level widget and its UI is build using one or more children (widgets), which again build using its children widgets. This composability feature helps us to create a user interface of any complexity. For example, the widget hierarchy of the hello world application (created in previous chapter) is as specified in the following diagram −   Here the following points are worth notable − MyApp is the user created widget and it is build using the Flutter native widget, MaterialApp . MaterialApp has a home property to specify the user interface of the home page, which is again a user created widget, MyHomePage . MyHomePage is build using another flutter native widget, Scaffold Scaffold has two properties – bo

Flutter : Introduction

Image
  Introduction to Flutter Installation In this section, let us see how to install Flutter SDK and its requirement in a windows system. Step 1 − Go to URL, https://flutter.dev/docs/get-started/install/windows and download the latest Flutter SDK. As of April 2019, the version is 1.2.1 and the file is flutter_windows_v1.2.1-stable.zip. Step 2 − Unzip the zip archive in a folder, say C:\flutter\ Step 3 − Update the system path to include flutter bin directory. Step 4 − Flutter provides a tool, flutter doctor to check that all the requirement of flutter development is met. flutter doctor Step 5 − Running the above command will analyze the system and show its report as shown below − Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.706], locale en-US) [√] Android tool chain - develop for Android devices (Android SDK version 28.0.3) [√] Android Studio (version 3.2) [√] VS Code, 64-bit editio

Dart: Functions

Image
  Functions Functions let you package multiple related lines of code into a single body that you can summon to avoid repeating those lines of code throughout your Dart application: A function consists of a return type , a function name , a parameter list in parentheses, and then a function body enclosed in braces. The code you're turning into the function goes inside the braces. When you call the function, you pass in arguments that match the types of the parameters of the function. Write a new function in DartPad that will just check to see if a given string is banana. bool isBanana( String fruit) { return fruit == 'banana' ; } The function uses return to return a bool value determined by the argument passed to the function. This function will always return the same value for any given input. If a function does not need to return a value, you can set the return type to void , such as for the main function.   Optional Parameters If a parameter to a funct

Dart: Control Flow

Image
  Control Flow Control flow lets you dictate that certain lines of code are executed, skipped over, or repeated. Control flow is handled in Dart with conditionals and loops . Conditionals The most basic form of control flow is deciding whether to execute or skip over certain parts of your code, depending on conditions that occur as your program runs. The language construct for handling conditions is the if / else statement. if / else in Dart looks nearly identical to the use in other C-like languages. Suppose you have an animal variable that's currently a fox. While Loops Loops let you repeat code a certain number of times or based on certain conditions. The latter are handled by while loops . There are two forms of while loop in Dart, while and do-while . The difference is that for while , the loop condition is before the code block, and in do-while the condition is after. So for do-while , the code block is guaranteed to run at least one time. Create a variable i

Tour of Dart

Image
  Getting Started DartPad is setup like a typical IDE. There is: An Editor pane on the left A Run button to run code in the editor A Console on the upper right showing output An Info panel on the bottom right showing information highlighted code A Samples dropdown to show some sample code A Share button you can use to share DartPad files you’ve created The main function is preceded by a return type, which in Dart is void , meaning nothing is returned. The parentheses after main indicate that this is a function definition, and the curly braces contain the body of the function. Inside main , you add the Dart code for your program. Variables, Comments, and Data Types The first thing we’ll add to main is a variable assignment statement. Variables hold the data that your program will work on. You can think of a variable like a box in your computer’s memory that holds a value. Each box has a name, the name for the variable. You use the var keyword in Dart to denote a variab

Introduction: Dart

Image
  What is Dart? Dart is a client-optimized language for fast apps on any platform  Dart is an open-source general-purpose programming language. It is originally developed by Google. Dart is an object-oriented language with C-style syntax. It supports programming concepts like interfaces, classes, unlike other programming languages Dart doesn’t support arrays. Dart collections can be used to replicate data structures such as arrays, generics, and optional typing. Dart is a single-threaded language with an Event loop much like JavaScript in your browser and Node.js. But it supports creating other threads to launch background jobs AKA asynchronous programming.   Setting Up the Local Environment Using the Text Editor Examples of a few editors include Windows Notepad, Notepad++, Emacs, vim or vi, etc. Editors may vary from one Operating System to another. The source files are typically named with the extension ".dart". Installing the Dart SDK The current

Introduction: App Development Components

Image
Mobile applications are no longer just the apps for the Smartphones! With the evolution of Internet of Technology (IoT), the same applications can now run on smart watch, smart TV, wrist bands and many other such platforms. Because of this recent revolution, mobile applications have become the cornerstone of the whole cognitive ecosystem. But as it is said that every coin has two sides, on one end where the reach of the mobile applications and its access is increasing, there is also an arising need that the applications cater smooth navigation amongst all the platforms and devices and have seamless front-end User Interface for satisfactory User Experience. What Is Flutter? Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Features: Fast Development Paint your app to life in milliseconds with Sta