Database Concepts

1. Tutorial

Flutter provides many advanced packages to work with databases. The most important packages are − In this chapter, let us discuss each of them in detail. SQLite SQLite database is the de-facto and standard SQL based embedded database engine. It is small and time-tested database engine. sqflite package provides a lot of functionality to work efficiently with SQLite database. It provides standard methods to manipulate SQLite database engine. The core functionality provided by sqflite package is as follows − Let us create a product application to store and fetch product information from a standard SQLite database engine using sqflite package and understand the concept behind the SQLite database and sqflite package. Use the latest version number of sqflite in place of any Cloud Firestore Firebase is a BaaS app development platform. It provides many feature to speed up the mobile application development like authentication service, cloud storage, etc., One of the main feature of Firebase is Cloud Firestore, a cloud based real time NoSQL database. Flutter provides a special package, cloud_firestore to program with Cloud Firestore. Let us create an online product store in the Cloud Firestore and create a application to access the product store. flutter: assets: – assets/appimages/floppy.png – assets/appimages/iphone.png – assets/appimages/laptop.png – assets/appimages/pendrive.png – assets/appimages/pixel.png – assets/appimages/tablet.png

October 12, 2024 / 0 Comments
read more

Introduction to Package

1. Tutorial

Dart’s way of organizing and sharing a set of functionality is through Package. Dart Package is simply sharable libraries or modules. In general, the Dart Package is same as that of Dart Application except Dart Package does not have application entry point, main. The general structure of Package (consider a demo package, my_demo_package) is as below − import ‘package:my_demo_package/my_demo_package.dart’ All Dart code files in the Package are simply Dart classes and it does not have any special requirement for a Dart code to include it in a Package. Types of Packages Since Dart Packages are basically a small collection of similar functionality, it can be categorized based on its functionality. Dart Package Generic Dart code, which can be used in both web and mobile environment. For example, english_words is one such package which contains around 5000 words and has basic utility functions like nouns (list nouns in the English), syllables (specify number of syllables in a word. Flutter Package Generic Dart code, which depends on Flutter framework and can be used only in mobile environment. For example, fluro is a custom router for flutter. It depends on the Flutter framework. Flutter Plugin Generic Dart code, which depends on Flutter framework as well as the underlying platform code (Android SDK or iOS SDK). For example, camera is a plugin to interact with device camera. It depends on the Flutter framework as well as the underlying framework to get access to camera. Using a Dart Package Dart Packages are hosted and published into the live server, https://pub.dartlang.org. Also, Flutter provides simple tool, pub to manage Dart Packages in the application. The steps needed to use as Package is as follows − Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career. Develop a Flutter Plugin Package Developing a Flutter Plugin is similar to developing a Dart application or Dart Package. The only exception is that the plugin is going to use System API (Android or iOS) to get the required platform specific functionality. As we have already learned how to access platform code in the previous chapters, let us develop a simple plugin, my_browser to understand the plugin development process. The functionality of the my_browser plugin is to allow the application to open the given website in the platform specific browser. my_browser.dart MyBrowserPlugin.java You can see a Browser app – Browser screen as shown in the screenshot shown below −

October 12, 2024 / 0 Comments
read more

Writing IOS Specific Code

1. Tutorial

Accessing iOS specific code is similar to that on Android platform except that it uses iOS specific languages – Objective-C or Swift and iOS SDK. Otherwise, the concept is same as that of the Android platform. Let us write the same application as in the previous chapter for iOS platform as well.

October 12, 2024 / 0 Comments
read more

Writing Android Specific Code

1. Tutorial

Flutter provides a general framework to access platform specific feature. This enables the developer to extend the functionality of the Flutter framework using platform specific code. Platform specific functionality like camera, battery level, browser, etc., can be accessed easily through the framework. The general idea of accessing the platform specific code is through simple messaging protocol. Flutter code, Client and the platform code and Host binds to a common Message Channel. Client sends message to the Host through the Message Channel. Host listens on the Message Channel, receives the message and does the necessary functionality and finally, returns the result to the Client through Message Channel. The platform specific code architecture is shown in the block diagram given below − The messaging protocol uses a standard message codec (StandardMessageCodec class) that supports binary serialization of JSON-like values such as numbers, strings, boolean, etc., The serialization and de-serialization works transparently between the client and the host. Let us write a simple application to open a browser using Android SDK and understand how Here, we have used platform.invokeMethod to invoke openBrowser (explained in coming steps). openBrowser has an argument, url to open a specific url. Here, we have created a message channel using MethodChannel class and used MethodCallHandler class to handle the message. onMethodCall is the actual method responsible for calling the correct platform specific code by the checking the message. onMethodCall method extracts the url from message and then invokes the openBrowser only when the method call is openBrowser. Otherwise, it returns notImplemented method. The complete source code of the application is as follows − main.dart MainActivity.java main.dart Run the application and click the Open Browser button and you can see that the browser is launched. The Browser app – Home page is as shown in the screenshot here −

October 12, 2024 / 0 Comments
read more

Animation

1. Tutorial

Animation is a complex procedure in any mobile application. In spite of its complexity, Animation enhances the user experience to a new level and provides a rich user interaction. Due to its richness, animation becomes an integral part of modern mobile application. Flutter framework recognizes the importance of Animation and provides a simple and intuitive framework to develop all types of animations. Introduction Animation is a process of showing a series of images / picture in a particular order within a specific duration to give an illusion of movement. The most important aspects of the animation are as follows − Animation Based Classes Flutter animation system is based on Animation objects. The core animation classes and its usage are as follows − Animation Generates interpolated values between two numbers over a certain duration. The most common Animation classes are − Here, controller controls the animation and duration option controls the duration of the animation process. vsync is a special option used to optimize the resource used in the animation. CurvedAnimation Similar to AnimationController but supports non-linear animation. CurvedAnimation can be used along with Animation object as below − Tween<T> Derived from Animatable<T> and used to generate numbers between any two numbers other than 0 and 1. It can be used along with Animation object by using animate method and passing actual Animation object. Here, controller is the actual animation controller. curve provides the type of non-linearity and the customTween provides custom range from 0 to 255. Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career. Work flow of the Flutter Animation The work flow of the animation is as follows − Working Application Let us write a simple animation based application to understand the concept of animation in Flutter framework. Here, Here, we have used FadeAnimation and MyAnimationWidget to animate the first two items in the list. FadeAnimation is a build-in animation class, which we used to animate its child using opacity concept.

October 12, 2024 / 0 Comments
read more

State Management

1. Tutorial

Managing state in an application is one of the most important and necessary process in the life cycle of an application. Let us consider a simple shopping cart application. A state management can be divided into two categories based on the duration the particular state lasts in an application. Navigation and Routing In any application, navigating from one page / screen to another defines the work flow of the application. The way that the navigation of an application is handled is called Routing. Flutter provides a basic routing class – MaterialPageRoute and two methods – Navigator.push and Navigator.pop, to define the work flow of an application. MaterialPageRoute MaterialPageRoute is a widget used to render its UI by replacing the entire screen with a platform specific animation. Here, builder will accepts a function to build its content by suppling the current context of the application. Navigation.push Navigation.push is used to navigate to new screen using MaterialPageRoute widget. Navigation.pop Navigation.pop is used to navigate to previous screen. Let us create a new application to better understand the navigation concept. Create a new Flutter application in Android studio, product_nav_app Let us rewrite our MyHomePage widget to work with Product model and to list all products using ListView. Here, we have used MaterialPageRoute to navigate to product details page. The complete code of the application is as follows − Run the application and click any one of the product item. It will show the relevant details page. We can move to home page by clicking back button. The product list page and product details page of the application are shown as follows −

October 12, 2024 / 0 Comments
read more

Introduction to Gestures

1. Tutorial

Gestures are primarily a way for a user to interact with a mobile (or any touch based device) application. Gestures are generally defined as any physical action / movement of a user in the intention of activating a specific control of the mobile device. Gestures are as simple as tapping the screen of the mobile device to more complex actions used in gaming applications. Some of the widely used gestures are mentioned here − Flutter provides an excellent support for all type of gestures through its exclusive widget, GestureDetector. GestureDetector is a non-visual widget primarily used for detecting the user’s gesture. To identify a gesture targeted on a widget, the widget can be placed inside GestureDetector widget. GestureDetector will capture the gesture and dispatch multiple events based on the gesture. Some of the gestures and the corresponding events are given below − Now, let us modify the hello world application to include gesture detection feature and try to understand the concept. Finally, Flutter also provides a low-level gesture detection mechanism through Listener widget. It will detect all user interactions and then dispatches the following events − Flutter also provides a small set of widgets to do specific as well as advanced gestures. The widgets are listed below −

October 12, 2024 / 0 Comments
read more

Introduction to Layouts

1. Tutorial

Since the core concept of Flutter is Everything is widget, Flutter incorporates a user interface layout functionality into the widgets itself. Flutter provides quite a lot of specially designed widgets like Container, Center, Align, etc., only for the purpose of laying out the user interface. Widgets build by composing other widgets normally use layout widgets. Let use learn the Flutter layout concept in this chapter. Type of Layout Widgets Layout widgets can be grouped into two distinct category based on its child − Let us learn both type of widgets and its functionality in the upcoming sections. Single Child Widgets In this category, widgets will have only one widget as its child and every widget will have a special layout functionality. For example, Center widget just centers it child widget with respect to its parent widget and Container widget provides complete flexibility to place it child at any given place inside it using different option like padding, decoration, etc., Single child widgets are great options to create high quality widget having single functionality such as button, label, etc., The code to create a simple button using Container widget is as follows − Here, we have used two widgets – a Container widget and a Text widget. The result of the widget is as a custom button as shown below − Let us check some of the most important single child layout widgets provided by Flutter − Some of the possible values of offsets are as follows − A sample code about offsets is shown below − Our hello world application is using material based layout widgets to design the home page. Let us modify our hello world application to build the home page using basic layout widgets as specified below − The modified code of the MyHomePage and MyApp widget is as below − Here, The final result of the code given above is a layout sample as shown below − Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career. Multiple Child Widgets In this category, a given widget will have more than one child widgets and the layout of each widget is unique. For example, Row widget allows the laying out of its children in horizontal direction, whereas Column widget allows laying out of its children in vertical direction. By composing Row and Column, widget with any level of complexity can be built. Let us learn some of the frequently used widgets in this section. Advanced Layout Application In this section, let us learn how to create a complex user interface of product listing with custom design using both single and multiple child layout widgets. For this purpose, follow the sequence given below − iPhone.png Pixel.png Laptop.png Tablet.png Pendrive.png Floppy.png Finally, Use the ProductBox widget in the MyHomePage widget as specified below − The final output of the application is as follows −

October 12, 2024 / 0 Comments
read more

Introduction to Widgets

1. Tutorial

As we learned in the earlier chapter, widgets are everything in Flutter framework. We have already learned how to create new widgets in previous chapters. In this chapter, let us understand the actual concept behind creating the widgets and the different type of widgets available in Flutter framework. Let us check the Hello World application’s MyHomePage widget. The code for this purpose is as given below − Here, we have created a new widget by extending StatelessWidget. Note that the StatelessWidget only requires a single method build to be implemented in its derived class. The build method gets the context environment necessary to build the widgets through BuildContext parameter and returns the widget it builds. In the code, we have used title as one of the constructor argument and also used Key as another argument. The title is used to display the title and Key is used to identify the widget in the build environment. Here, the build method calls the build method of Scaffold, which in turn calls the build method of AppBar and Center to build its user interface. Finally, Center build method calls Text build method. For a better understanding, the visual representation of the same is given below − Widget Build Visualization In Flutter, widgets can be grouped into multiple categories based on their features, as listed below − Let us discuss each of them in detail now. Platform specific widgets Flutter has widgets specific to a particular platform – Android or iOS. Android specific widgets are designed in accordance with Material design guideline by Android OS. Android specific widgets are called as Material widgets. iOS specific widgets are designed in accordance with Human Interface Guidelines by Apple and they are called as Cupertino widgets. Some of the most used material widgets are as follows − Some of the most used Cupertino widgets are as follows − Layout widgets In Flutter, a widget can be created by composing one or more widgets. To compose multiple widgets into a single widget, Flutter provides large number of widgets with layout feature. For example, the child widget can be centered using Center widget. Some of the popular layout widgets are as follows − We will check the layout widgets in detail in the upcoming Introduction to layout widgets chapter. State maintenance widgets In Flutter, all widgets are either derived from StatelessWidget or StatefulWidget. Widget derived from StatelessWidget does not have any state information but it may contain widget derived from StatefulWidget. The dynamic nature of the application is through interactive behavior of the widgets and the state changes during interaction. For example, tapping a counter button will increase / decrease the internal state of the counter by one and reactive nature of the Flutter widget will auto re-render the widget using new state information. We will learn the concept of StatefulWidget widgets in detail in the upcoming State management chapter. Platform independent / basic widgets Flutter provides large number of basic widgets to create simple as well as complex user interface in a platform independent manner. Let us see some of the basic widgets in this chapter. Text Text widget is used to display a piece of string. The style of the string can be set by using style property and TextStyle class. The sample code for this purpose is as follows − Text widget has a special constructor, Text.rich, which accepts the child of type TextSpan to specify the string with different style. TextSpan widget is recursive in nature and it accepts TextSpan as its children. The sample code for this purpose is as follows − The most important properties of the Text widget are as follows − Image Image widget is used to display an image in the application. Image widget provides different constructors to load images from multiple sources and they are as follows − The easiest option to load and display an image in Flutter is by including the image as assets of the application and load it into the widget on demand. The loaded image is as shown below − The most important properties of the Image widget are as follows − Icon Icon widget is used to display a glyph from a font described in IconData class. The code to load a simple email icon is as follows − The complete source code to apply it in hello world application is as follows − The loaded icon is as shown below −

October 12, 2024 / 0 Comments
read more

Introduction to Dart Programming

1. Tutorial

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. The following code shows a simple Dart program − Variables and Data types Variable is named storage location and Data types simply refers to the type and size of data associated with variables and functions. Dart uses var keyword to declare the variable. The syntax of var is defined below, The final and const keyword are used to declare constants. They are defined as below − Dart language supports the following data types − The list shown above produces [1,2,3,4,5] list. Map can be defined as shown here − Decision Making and Loops A decision making block evaluates a condition before the instructions are executed. Dart supports If, If..else and switch statements. Loops are used to repeat a block of code until a specific condition is met. Dart supports for, for..in , while and do..while loops. Let us understand a simple example about the usage of control statements and loops − The above code prints the even numbers from 1 to 10. Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career. Functions A function is a group of statements that together performs a specific task. Let us look into a simple function in Dart as shown here − The above function adds two values and produces 7 as the output. Object Oriented Programming Dart is an object-oriented language. It supports object-oriented programming features like classes, interfaces, etc. A class is a blueprint for creating objects. A class definition includes the following − Now, let us create a simple class using the above definitions −

October 12, 2024 / 0 Comments
read more

Posts pagination

Previous 1 … 111 112 113 … 445 Next