Google search engine
Home Blog Page 40

Razorpay Payment In Flutter

Razor Pay is one of the best payment gateways which provided plugin in a flutter. It was the most straightforward to integrate in-product payment widget that kicked us off with Razorpay yet it was the quick and dependable help for both issue settlement and on-boarding new highlights that have kept us cooperating with them!.

Assemble a protected installment arrangement on your site or portable application with Razorpay and get installments from your clients utilizing different installment techniques on your Checkout structure. You can follow installments at each progression of its life cycle and effectively manage them.

How to Generate API Key

  1. Sign in to your Dashboard with suitable credentials.
  2. Select the mode (Test or Live) for which you need to create the API key
  3. Explore to Settings → API Keys → Generate Key to create a key for the chose mode.

Note:
You need to produce separate API Keys for the test and live modes. No cash is deducted from your record in test mode.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec.yaml file.

dependencies:

razorpay_flutter: latest version

Step 2: Import

import 'package:razorpay_flutter/razorpay_flutter.dart';

Minimum Version Requirement:

For Android, guarantee that the base minimum API level for your app is 19 or higher.

For iOS, guarantee that the base minimum deployment target for your app is iOS 10.0 or higher.Likewise, remember to enable bitcode for your project.

Step 3Run flutter packages get in the root directory of your app.

Now core concepts of the Razorpay Payment.

You need to implement it in your code respectively:

Create Razorpay instance:

Use this code to create a Razorpay instance.

_razorpay = Razorpay();

Event Listeners:

The plugin utilizes event-based communication and transmits events when payments fail or succeed.

The event names are uncovered using the constants EVENT_PAYMENT_SUCCESSEVENT_PAYMENT_ERROR and EVENT_EXTERNAL_WALLET from the Razorpay class.

Use the on(String event, Function handler) method on the Razorpay instance to append event listeners.

_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);

Handler:

The handlers would be defined in the class and handle the different responses.

In this handler, you can add one more dependencies

fluttertoast: ^latest version

then again run flutter packages get in the root directory of your app.

Setup Options:

Introduce the details in options and pass your Razorpay key Id here. if you don’t have one go here.

To clear event listeners, use the clear method on the Razorpay instance.

_razorpay.clear(); // Removes all listeners

Error Codes:

The error codes have been uncovered as integers by the Razorpay class.

The error code is accessible as the code field of the PaymentFailureResponse the instance passed to the callback.

  1. NETWORK_ERROR: There was a network error. For example, loss of internet connectivity.
  2. INVALID_OPTIONS: An issue with options passed in Razorpay.open.
  3. PAYMENT_CANCELLED: The user canceled the payment.
  4. TLS_ERROR: The device does not support TLS v1.1 or TLS v1.2.
  5. UNKNOWN_ERROR: An unknown error occurred.

Event Names:

The event names have been uncovered as strings by the Razorpay class.

> EVENT_PAYMENT_SUCCESS: The payment was successful.

> EVENT_PAYMENT_ERROR: The payment was not successful.

> EVENT_EXTERNAL_WALLET: An external wallet was selected.

Payment Success Response:

  • Payment IdstringThe ID for the payment.
  • Order IdstringThe order ID if the payment was for an order, otherwise null.
  • Signature:string The signature to be used for payment verification. Only valid for orders, otherwise null.

Payment Failure Response:

=> Codeinteger The error code.

=>Message: string The error message.

External Wallet Response:

Wallet Namestring The name of the external wallet selected.

https://gist.github.com/ShaiqAhmedkhan/ec34b4c903b313b927301761c44c1a6f#file-cart-dart

This is a small bakery flutter example will integrate Razorpay payment, in this code, you will see how to add Razorpay in our code and how to get an order with online payment. This below video shows how Razorpay Payment will work.

So this was the basic example of the Bakery app integrated with Razorpay Payment where we did a simple example and you can learn it and also you can do it.


Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.

Click the GitHub link below to find the source code of the Bakery App integrated with Razorpay.

flutter-devs/Flutter_Bakery_App_Demo
This App has a decent UI as well as we have integrated Razor Payment Gateway — flutter-devs/Flutter_Bakery_App_Demogithub.com


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Stripe Payment In Flutter

Related: Payment Gateway Testing with Test Cases In Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Built-in Explicit Animations in Flutter

0

In our last post, we figured out how to do some marvellous animations movements utilizing Flutter’s staggered animationsAnimatedFoo and TweenAnimationBuilderenabled you to drop some fundamental animations into your application. These animations commonly go one way, “tweening” from a beginning to an end, where they stop. Off-camera, Flutter is taking control, accepting expectations and discarding any requirement for you to stress over the change starting with one thing then onto the next.

This works superbly for some animations objectives, yet in some cases that ever-forward bolt of time leaves us feeling transiently bolted. All in all, as we stop and think about the laws of thermodynamics and the unavoidable warmth demise of the universe, wouldn’t it be decent on the off chance that we could switch time, and do everything once more?

Transition widgets are a lot of Flutter widgets whose names all end in — you speculated it — Transition. ScaleTransitionSizeTransition DecoratedBoxTransition, and that’s just the beginning. They look and feel a great deal like our AnimateBlah widgets. PositionedTransition, for example, animates a widget’s progress between various positions. This is a lot of like, however, there is one significant contrast: these Transition widgets are augmentations of AnimatedWidget. This makes them explicit animations.

An image of Sun(GalaxyWay) just sitting on the galaxy, not rotating

RotationTransition

The RotationTransition widget is a helpful one that deals with the entirety of the trigonometry and changes math to make things turn. Its constructor just takes three things:

// [Most of] RotationTransition’s constructor
RotationTransition({
Widget child,
Alignment alignment,
Animation<double> turns,
})

child — the widget we need to turn. The galaxy way, so we’ll put it there: Next, we have to give RotationTransition the point our sun turns around. Our sun is generally in the centre of the picture where we’d ordinarily anticipate. Along these lines, we’ll give an arrangement of focus, making the entirety of our rotational math “adjusted” to that point.

RotationTransition(
turns: _repeatingAnimationLong,
child: GalaxyWay(),
alignment: Alignment.center,
),

Not to stress! This is a piece of what makes RotationTransition and the various Transition widgets, an explicit animation. We could achieve a similar rotation impact with an AnimatedContainer and a change, however then we’d turn once and afterwards stop. With our explicit animations movements, we have control of time and can make it so our sun spins constantly.

The turns property expects something that gives it a value and educates it when that value changes. An Animation<double> is just that. For RotationTransition, the value analyzes how regularly we’ve turned, or even the more explicitly, the level of one revolution finished.

Creating an AnimationController

Perhaps the most effortless approaches to get an Animation<double> is to make an AnimationController, which is a controller for animation. This controller handles tuning in for ticks¹ and gives us some helpful powers over what the movement is doing.

We’ll have to make this in a stateful widget since keeping an idea about the controller will be significant in our imminent future. Since AnimationController likewise has its own state to manage, we initialize it in initState, and dispose of it in dispose().

There are two parameters we should provide for Animation Controller’s constructor. The first is a length, which is to what extent our explicit animation movement keeps going. The entire explanation we’re here is that we need an article to disclose to us how far along we are in a solitary revolution. Of course, AnimationController “emits” values from 0.0 to 1.0. What number of and how granular those qualities are relied upon to what extent we need a single rotation to take. Luckily, Dart gives us a Duration class to utilize. For this demo, we should have the sun turning somewhere close to 5 seconds and 230 million years for every revolution. What about 15 seconds for each turn at that point?

_animationController = AnimationController(
duration: Duration(seconds: 15),
// TODO: finish constructing me.
);

On the off chance that we left things at that, not a lot occurs. That is on the grounds that we’ve been given a controller, yet haven’t pressed any of its buttons! We need our sun to turn forever, isn’t that so? For that, we’ll simply ask the controller to continually repeat the animation movement.

_animationController = AnimationController(
duration: Duration(seconds: 15),
vsync: this,
)..repeat();

Making use of an AnimationController

Allowing anybody to control the sun appears to be a piece excessively lenient, however, so I’m going to make it an easter egg. I’ll add a sibling to the sun that is a basic button, covered up off background in the animation, and I’ll pass it a reference to our controller so that inside its onTap listener, we can stop or restart the movement.

The controller maintains — among other things — the status of the animation, which we can check and stop in case we’re running or restart in case we’re definitely not. What’s more, there you go! By utilizing an animation controller, we’re ready to control the animation movement on request. In any case, that is not everything you can do with the controller.

With it, you can likewise animate to (or in reverse from) a particular value, flying the animation movement forward with a given speed, or control various animations with a similar controller.

This was only our first taste of explicit animations in Flutter. We saw how a Transition widget functionsAnimationControllerto give some directionality and command over how our animation functions. In future posts, we’ll be jumping further into explicit animations and how to get considerably more altered.

here in the video posted below, you will see how explicit animation was working and when you tap anywhere in that screen then it pause the animation and the whole animation will freeze and then you tap again anywhere in that screen then it resumes animation, you can control the speed of animation and also the movement of directions.

So this was the basic example of Explicit Animation where we did a simple example and you can learn it and also you can do it.


Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.

Click the GitHub link below to find the source code of the Explicit Animation.

flutter-devs/ExplicitAnimations
A new Flutter application. This project is a starting point for a Flutter application. A few resources to get you…github.com


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Staggered Animation In Flutter

0

A staggered animation includes consecutive or covering animations.To make an staggered animation, to utilize a few/couple of Animation items.One Animation Controller controls all the Animations.Each Animation object shows the movement at some point or another of an Interval.For each preferred position being animated, make a Tween.

Staggered animations movements are a direct idea: visual changes occur as a progression of tasks, instead of at the same time. The activity may be simply consecutive, with one change occuring after the following, or it may somewhat or totally cover. It may likewise have holes, where no progressions happen.

Here is the demo video you can take a look staggered animationhttps://www.youtube.com/embed/0fFvnZemmh8?feature=oembed

In this video, you will see the accompanying animation movement of a single widget, which starts as a bordered blue square with marginally adjusted corners. The square runs they will blur and afterward change in square was broaden in measure and afterward square becomes taller while moving upwards and they will changes into an outskirt circle and the progressions shading blue to orange,after walking forward, the activity runs backward.

Structure of a staggered animation

The entire of the animations are pushed by methods for a similar Animation Controller.Regardless of the way extensive the animation movement keeps going in genuine time, the controller’s qualities should be among zero.0 and 1.0, comprehensive.

Every animation movement has an Interval among zero.Zero and 1.0, comprehensive.

For every having a place that animates in an interval, make a Tween. The Tween determines the beginning and give up values for that assets.The Tween produces a Animation thing that is made do with the guide of the controller.

To set up the animation:

  • Make a Animation Controller that deals with every one of the Animations.
  • Make a Tween for each having a place being animated.
  • The Tween characterizes different values.
  • The Tween’s animate technique requires the decide controller, and produces a Animation for that assets.
  • Determine the interval time frame at the Animation’s curve assets.

How to use Staggered animation in Flutter:

The following code makes a tween for the avatarSize property. It constructs a CurvedAnimation, determining an elasticOut curve. See Curves for other accessible pre-characterized animation Curves.

avatarSize = Tween<double>(
begin: 50.0,
end: 150.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.125, 0.250,
curve: Curves.elasticOut,
),
),
),

Animation controller and Animation define an instance of the class AnimationController for the animation controller and five instances of the class Animation to handle animations (double to get a progressive value from 0 to 1).

final AnimationController controller;
final Animation<double> barHeight;
final Animation<double> avatarSize;
final Animation<double> titleOpacity;
final Animation<double> textOpacity;
final Animation<double> imageOpacity;

Animation initializing override the initState method and define the parameters for the animation. For this situation, the duration is set to three seconds.

_controller = AnimationController(
duration: const Duration(milliseconds: 3500),
vsync: this,);

How to implement in dart file:

You need to implement it in your code respectively:

This stateful widget, Staggered Trekking Animation add as a mixin the SingleTickerProviderStateMixin and makes the AnimationController was determining a 3500 ms duration. It will plays the animation movement and builds the non-animating portion of the widget. The animation start when a tap is distinguished in the screen. The animation movement runs forward and then reverse automatically.

https://gist.github.com/ShaiqAhmedkhan/99acdd5d7303e8711c3bd17cacd75d05#file-staggered_trekking_animation-dart

In Staggered Trekking Enter Animation, using the tween’s current values and next you will make a Stateless widget,Staggered Trekking make a build() function an AnimatedBuilder—this widget for building animations. We create a function named _buildAnimation() and it work UI updates and assigns it to its builder property.

https://gist.github.com/ShaiqAhmedkhan/cb4e10462a536eeaf01cc2def10b4578#file-staggered_trekking_enter_animation-dart

AnimatedBuilder will listen to the notifications from the animation controller will marking the widget for the values change. For each tick of the animation, the values were updated, resulting in a call to _buildAnimation().

here in the video posted below, you will see how staggered animation were working and when you tap anywhere in that screen it starts animation and run reverse automatically animation, you can control the speed of animation also.

So this was the basic example of Staggered Animation where we did a simple example and you can learn it.

Click the GitHub link below to find the source code of the Staggered Animation.

flutter-devs/Flutter-StaggeredAnimation
You can’t perform that action at this time. You signed in with another tab or window. You signed out in another tab or…github.com


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.


Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.

Parsing JSON in Flutter

0

For those of you who do not know what is Flutter then

Flutter is an open-source mobile application development SDK created by Google. It is used to develop applications for Android and iOS.

or you can visit https://flutter.dev

let’s talk about JSON parsing in flutter.

I know it is really confusing for beginners to understand how to parse JSON data.

Let’s Start with a JSON example

Suppose I want to access the articles list but the articles have many attributes and we need to parse the article array into our app.

Let’s see what we have in the article

So How we are going to do that?

Step 1: Create a PODO

First of all, we have to create a PODO (Plain Old Dart Object) for a particular article.

To access source in the Article we also have to create a PODO for Source.

https://gist.github.com/ashishrawat2911/c5eeb2f47a7b24b437670f1aeacf81ef#file-article-dart

Step 2: Make the network request

I am using the NewsApi to retrieve the JSON data

I have the URL and I want the response when I request to the URL.

Step 3: Decode the response

Now I have the response I can get the list of articles.

If you are an android developer and you know the traditional way of parsing the JSON data then you must remember that first we retrieve the JSON data and get the JSON array then iterate the JSON array and map to the Java objects we have done the same here.

var rest = data["articles"] as List;

Now the rest will have the JSON array and we will iterate the JSON array and map to the Dart objects.

Step 3: Map the JSON objects to Dart Objects

Complete method of parsing the JSON array

https://gist.github.com/ashishrawat2911/8a8cd94761b491e6876c8b1308f0cb78#file-jsonmethod-dart

Complete code.

https://gist.github.com/ashishrawat2911/0787c959bd151270bef9bee7ad546b37#file-newsjson-dart

The final app will look like this:

If you still have any problem, I have linked my Github Repo

ashishrawat2911/Flutter-NewsWeb
Contribute to ashishrawat2911/Flutter-NewsWeb development by creating an account on GitHub.github.com

Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.
Connect with me on Linkedin and Github


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Flutter Rendering Widgets Using JSON Data

Related: Automating JSON To Dart Class In Flutter

Related: Automatic Generate JSON Serializable In Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Cupertino (iOS-style) ActionSheet in Flutter | Know Your Widgets

0

This is the first article of our Know Your Widgets series.

Know Your Widgets is a brand new series in which we’ll be explaining all the important widgets that you should know when starting to develop applications in Flutter.

We have decided to dive into all the flutter widgets and try to explain each one to you.

In this article, I am going to show you How to use CupertinoActionSheet.

If you are wondering what is Cupertino then

Cupertino in Flutter is a set of widgets implementing the current iOS design language.

Have a look

Cupertino ActionSheet

An action sheet is a specific style of alert that presents the user with a set of two or more choices related to the current context.

An action sheet can have a title, an additional message, and a list of actions. The title is displayed above the message and the actions are displayed below this content.

This action sheet styles its title and message to match standard iOS action sheet title and message text style.

First of all, we need to import the Cupertino package

package:flutter/cupertino.dart

Everything in flutter is a Widget so is CupertinoActionSheet, we can use it anywhere in the layout but we want our ActionSheet to show it in with a modal sheet.

So we will use

showCupertinoModalPop

In this, we have two required parameters

@required BuildContext context,
@required WidgetBuilder builder,

Now

showCupertinoModalPopup( 
context: context,
builder: (BuildContext context) => CupertinoActionSheet());

In CupertinoActionSheet we have title:, message: and actions:

CupertinoActionSheet(                                 
title: const Text('Choose Options'), message: const Text('Your options are'), actions: <Widget>[]
);

Inside actions: <Widget>[] we will list all the options that we are required to show.

To show a particular option item in the actions: <Widget>[] , we will use a CupertinoActionSheetAction()widget.

CupertinoActionSheetAction( 
child: const Text(‘Option 1’),
onPressed: () {
//do some action
}
);

We can add as many as CupertinoActionSheetAction()inside actions: <Widget>[].

Now the code will look like this

showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
title: const Text('Choose Options'),
message: const Text('Your options are '),
actions: <Widget>[
CupertinoActionSheetAction(
child: const Text('One'),
onPressed: () {
Navigator.pop(context, 'One');
},
),
CupertinoActionSheetAction(
child: const Text('Two'),
onPressed: () {
Navigator.pop(context, 'Two');
},
)
],
),
);
CupertinoActionSheetAction in CupertinoActionSheet

In CupertinoActionSheet()

we also have cancel button parameter in, it just separates a single option with other options inactions: <Widget>[]

cancelButton: CupertinoActionSheetAction(            
child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context, 'Cancel');
},
)),

it will look like this

Cancel in CupertinoActionSheet

Now Let’s see the actual code

showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
title: const Text('Choose Options'),
message: const Text('Your options are '),
actions: <Widget>[
CupertinoActionSheetAction(
child: const Text('One'),
onPressed: () {
Navigator.pop(context, 'One');
},
),
CupertinoActionSheetAction(
child: const Text('Two'),
onPressed: () {
Navigator.pop(context, 'Two');
},
)
],
cancelButton: CupertinoActionSheetAction(
child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context, 'Cancel');
},
)),
);

Now You are good to go

Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Developing Web Apps Using Flutter

Related: Flutter App for Desktop

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Know Your Widgets: Container in Flutter

0

If you are new to flutter you must be wondering what is Container then,

A Container is a convenience widget that combines common painting, positioning, and sizing widgets.

You can use Container to any widgets to add some styling properties.

Let’s look into the parameters of a container.

Container({
Key key,
this.alignment,
this.padding,
Color color,
Decoration decoration,
this.foregroundDecoration,
double width,
double height,
BoxConstraints constraints,
this.margin,
this.transform,
this.child,
})

That’s a lot of properties, but no worries we have everything sorted.

Let’s dive into each and every property.

Color :

Center(
child: Container(
color: Colors.amber,
),
),

Child :

We can only add one child to the Container as it is a Single-child layout widget.

Container(
color: Colors.amber,
child: FlutterLogo(
size: 400,
),

),
)

Alignment Property:

You can use Alignment, FractionalOffset, and AlignmentDirectional class for the alignment property in Container.

Alignment

In Alignment (0,0) means the center of the screen so if you assign Alignment(0,0) to the alignment property then it will be on the center of the screen.

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
alignment: Alignment(0, 0),
),
)
Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: Alignment(1.0, 1.0),
)
Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: Alignment(-1.0, -1.0),
)
child: Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: Alignment(1.0, -1.0),
)
Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: Alignment(-1.0, 1.0),
)

You can use constants that are already defined by Alignment Class.

Example:

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: Alignment.bottomRight,
)

There are many other constants :

// The top left corner.
static const Alignment topLeft = Alignment(-1.0, -1.0);
// The center point along the top edge.
static const Alignment topCenter = Alignment(0.0, -1.0);
// The top right corner.
static const Alignment topRight = Alignment(1.0, -1.0);
// The center point along the left edge.
static const Alignment centerLeft = Alignment(-1.0, 0.0);
// The center point, both horizontally and vertically.
static const Alignment center = Alignment(0.0, 0.0);
// The center point along the right edge.
static const Alignment centerRight = Alignment(1.0, 0.0);
// The bottom left corner.
static const Alignment bottomLeft = Alignment(-1.0, 1.0);
// The center point along the bottom edge.
static const Alignment bottomCenter = Alignment(0.0, 1.0);
/// The bottom right corner.
static const Alignment bottomRight = Alignment(1.0, 1.0);

FractionalOffset

You can also user FractionalOffset with the alignment property of the Container.

In FractionalOffset, (0,0) means the top left of the screen so if you assign Alignment(0,0) to the alignment property then it will be on the top left of the screen.

FractionalOffset(double dx, double dy)

Example:

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: FractionalOffset(0,0),
)

You can use constants that are already defined by FractionalOffset Class.

Example:

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: FractionalOffset.topLeft,
)

There are many other constants :

/// The top left corner.
static const FractionalOffset topLeft = FractionalOffset(0.0, 0.0);
/// The center point along the top edge.
static const FractionalOffset topCenter = FractionalOffset(0.5, 0.0);
/// The top right corner.
static const FractionalOffset topRight = FractionalOffset(1.0, 0.0);
/// The center point along the left edge.
static const FractionalOffset centerLeft = FractionalOffset(0.0, 0.5);
/// The center point, both horizontally and vertically.
static const FractionalOffset center = FractionalOffset(0.5, 0.5);
/// The center point along the right edge.
static const FractionalOffset centerRight = FractionalOffset(1.0, 0.5);
/// The bottom left corner.
static const FractionalOffset bottomLeft = FractionalOffset(0.0, 1.0);
/// The center point along the bottom edge.
static const FractionalOffset bottomCenter = FractionalOffset(0.5, 1.0);

AlignmentDirectional

You can also user AlignmentDirectional with the alignment property of Container

AlignmentDirectional(this.start, this.y)

An offset that’s expressed as a fraction of a Size, but whose horizontal component is dependent on the writing direction.

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: AlignmentDirectional(-1,1),
)

You can use constants that are already defined AlignmentDirectional Class

Example:

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),alignment: AlignmentDirectional.topEnd,
)

There are many other constants :

/// The top corner on the "start" side.
static const AlignmentDirectional topStart = AlignmentDirectional(-1.0, -1.0);
/// The center point along the top edge.
///
/// Consider using [Alignment.topCenter] instead, as it does not need
/// to be [resolve]d to be used.
static const AlignmentDirectional topCenter = AlignmentDirectional(0.0, -1.0);
/// The top corner on the "end" side.
static const AlignmentDirectional topEnd = AlignmentDirectional(1.0, -1.0);
/// The center point along the "start" edge.
static const AlignmentDirectional centerStart = AlignmentDirectional(-1.0, 0.0);
/// The center point, both horizontally and vertically.
///
/// Consider using [Alignment.center] instead, as it does not need to
/// be [resolve]d to be used.
static const AlignmentDirectional center = AlignmentDirectional(0.0, 0.0);
/// The center point along the "end" edge.
static const AlignmentDirectional centerEnd = AlignmentDirectional(1.0, 0.0);
/// The bottom corner on the "start" side.
static const AlignmentDirectional bottomStart = AlignmentDirectional(-1.0, 1.0);
/// The center point along the bottom edge.
///
/// Consider using [Alignment.bottomCenter] instead, as it does not
/// need to be [resolve]d to be used.
static const AlignmentDirectional bottomCenter = AlignmentDirectional(0.0, 1.0);
/// The bottom corner on the "end" side.
static const AlignmentDirectional bottomEnd = AlignmentDirectional(1.0, 1.0);

Constraint Property:

Container(
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
alignment: Alignment.center,
constraints: BoxConstraints(
maxHeight: 400,
maxWidth: 400,
minHeight: 100,
minWidth: 100,
),

)

Decoration Property:

The decoration parameter is to paint behind the child.

We can use the BoxDecoration class to decorate the container.

To know more about B0xDecoration I have linked a blog below.

Flutter — BoxDecoration Cheat Sheet

Margin Property:

A margin is a property specifying to add space to surround the container.

We do it with EdgeInsets.

EdgeInsets.all

EdgeInsets.all(double value)

Example :

Container(
alignment: Alignment.center,
color: Colors.amber,
child: FlutterLogo(
size: 200,
),margin: EdgeInsets.all(50),
)

EdgeInsets.symmetric

EdgeInsets.symmetric({ double vertical = 0.0,
double horizontal = 0.0 })

Example:

Container(
alignment: Alignment.center,
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
margin: EdgeInsets.symmetric(horizontal: 70, vertical: 30),
)

EdgeInsets.fromLTRB :

EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom)

Example :

Container(
alignment: Alignment.center,
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
margin: EdgeInsets.fromLTRB(20, 30, 40, 50),
)

EdgeInsets.only:

EdgeInsets.only({
this.left = 0.0,
this.top = 0.0,
this.right = 0.0,
this.bottom = 0.0
});

Example :

Container(
alignment: Alignment.center,
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
margin: EdgeInsets.only(left: 70, bottom: 50),
)

Padding Property :

When we add padding to a widget, we just add space inside of a widget, unlike margin which adds space outside the widget.

Container(
alignment: Alignment.center,
color: Colors.amber,
child: FlutterLogo(
size: 200,
),
padding: EdgeInsets.only(left: 70, bottom: 50),
)

Before and after padding

EdgeInsets properties will be the same as of margin.


You must have got an overview of a Container widget.

Now you are good to go.

Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Dialog Using GetX in Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Know Your Widgets: Scaffold in Flutter

0

If you’re here then you must’ve just started to work in Flutter and might have come across the Scaffold ‘thing’ almost everytime, like EVERYTIME and I am pretty sure you must’ve come across various ambiguous questions.

class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Drawer Module"),
),
drawer: Drawer(
child: ListView(
children: <Widget>[
new UserAccountsDrawerHeader(
accountName: Text("xyz"),
accountEmail: Text("xyz@gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.white,
child: Text("xyz"),
),
otherAccountsPictures: <Widget>[
new CircleAvatar(
backgroundColor: Colors.white,
child: Text("A"),
)

],
),

This is just a example of a module showing the root and basic requirement of scaffold in building an app in Flutter.

So, you must be curious to know about the Scaffold widget and it’s properties in flutter. Don’t worry we got your back, this blog will give you the basic knowledge about Scaffold and how to use it while creating your basic module.

Let’s go…..

What is Scaffold?

A Scaffold Widget provides a framework which implements the basic material design visual layout structure of the flutter app. It provides APIs for showing drawers, snack bars and bottom sheets. Have a look at its constructor and the properties it has. We are going to overview it’s parameters one by one.

//Constructor of Scaffold
const Scaffold({
Key key,
this.appBar,
this.body,
this.floatingActionButton,
this.floatingActionButtonLocation,
this.floatingActionButtonAnimator,
this.persistentFooterButtons,
this.drawer,
this.endDrawer,
this.bottomNavigationBar,
this.bottomSheet,
this.backgroundColor,
this.resizeToAvoidBottomPadding = true,
this.primary = true,
})

Scaffold contains various functionality from giving an appbar, a floating button, a drawer, background color, bottom navigation bar, footer buttons,body. Now, let’s explore them individually:

  • appBar
    An appBar is to display at the top of the scaffold it’s one of the primary content of Scaffold without which a scaffold widget is incomplete. It defines what has to be displayed at the top of the screen. appBar uses the AppBar widget properties through Scaffold.appBar. This AppBar widget itself has various properties like title, elevation,brightness etc to name a few.
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Scaffold'),
),

Here, the title property of AppBar uses Text widget to display the text on the app bar.

Fig 1: Display an AppBar
  • body
    body is the other primary and minimum required property of the scaffold which signifies the area below the app bar and behind the floatingActionButton and drawer. Any widget in the body of scaffold is positioned at the top-left corner by default.
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Scaffold'),
),
body: Center(
child: Text("This is Homepage",
style: TextStyle(
color: Colors.black,
fontSize: 40.0,
fontStyle: FontStyle.italic,
),
),
),

Here, the body property of the Scaffold is used to display a text “This is HomePage”. The Centre widget is used to align the text at the centre of the body and a Text widget is used to give the text along with it’s style property which gives the text a color, fontsize and fontstyle. Don’t worry this blog isn’t about the Centre or Text or TextStyle widgets, they will be covered later.

Fig 2: Text displayed inside the body
  • floatingActionButton
    A floatingActionButton is a button displayed floating above body in the bottom right corner. It is a circular icon button that hovers over content to promote a primary action in the application. floatingActionButton uses the FloatingActionButton widget properties through Scaffold.floatingActionButton.
  @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Scaffold'),
),
body: Center(
child: Text(
"This is Homepage",
style: TextStyle(
color: Colors.black,
fontSize: 40.0,
fontStyle: FontStyle.italic,
),
),
),
floatingActionButton: FloatingActionButton(
elevation: 10.0,
child: Icon(Icons.add),
onPressed: (){
print('I am Floating button');
}
),
);
}

Here, the elevation property of the FloatingActionButton is used which gives shadow to the button and Icon widget is used to give an icon to the button. The onPressed property provides a callback that is called when the button is tapped, when you tap the button “ I am a Floating Button” gets printed on the console window refer Fig 4 below .

Fig 3: A floatingActionButton with an icon
Fig 4: onPressed callback is called when tapped
  • floatingActionButtonLocation
    By default, the floatingActionButton is positioned at the bottom right corner of the screen so as the name says floatingActionButtonLocation defines the position of the floatingActionButton using the predefined contants like,

centerDocked

floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,

centerFloat

floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,

endDocked

floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,

endFloat

floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
Fig 5: floatingActionButtonLocation constants
  • drawer
    A drawer is a panel displayed to the side of the body, often hidden on mobile devices. One usually has to swipe left to right or right to left to access the drawer. 
    It uses the Drawer widget properties which is a material design panel that slides in horizontally from the edge of a Scaffold to show navigation links in an application and this widget is used in scaffold using Scaffold.drawer property.
drawer: Drawer(
elevation: 16.0,
child: Column(
children: <Widget>[
UserAccountsDrawerHeader(
accountName: Text("xyz"),
accountEmail: Text("xyz@gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.white,
child: Text("xyz"),
),
otherAccountsPictures: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
child: Text("abc"),
)
],
),
ListTile(
title: new Text("All Inboxes"),
leading: new Icon(Icons.mail),
),
Divider(
height: 0.1,
),
ListTile(
title: new Text("Primary"),
leading: new Icon(Icons.inbox),
),
ListTile(
title: new Text("Social"),
leading: new Icon(Icons.people),
),
ListTile(
title: new Text("Promotions"),
leading: new Icon(Icons.local_offer),
)
],
),
),

Here, the drawer property of scaffold is used to create a drawer. We used various other widget inside this to make a little attractive drawer but don’t worry about all the other widgets, as we’ll be covering in the series.

Fig 6: drawer
  • persistentFooterButtons
    persistentFooterButtons is a list of buttons that are displayed at the bottom of the scaffold. These buttons are persistently visible, even if the body of the scaffold scrolls. They will be wrapped in a ButtonBar and are rendered above the bottomNavigationBar but below the body.
persistentFooterButtons: <Widget>[
RaisedButton(
elevation: 10.0,
onPressed: () {},
color: Colors.green,
child: Icon(
Icons.add,
color: Colors.white,
),
),
RaisedButton(
elevation: 10.0,
onPressed: () {},
color: Colors.blueGrey,
child: Icon(
Icons.clear,
color: Colors.white,
),
),
],

Here, persistentFooterButtons take a list of widgets or buttons. In this we have used the RaisedButton if you want you can use the FlatButton instead.

Fig 7: persistentFooterButtons
  • bottomNavigationBar
    bottomNavigationBar is used to display a navigation bar at the bottom of the scaffold. It is rendered below the persistentFooterButtons and the body.
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0,
fixedColor: Colors.teal,
items: [
BottomNavigationBarItem(
title: Text("Home"),
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
title: Text("Search"),
icon: Icon(Icons.search),
),
BottomNavigationBarItem(
title: Text("Add"),
icon: Icon(Icons.add_box),
),
],
onTap: (int index){
setState(() {
_currentIndex = index;
});
},
),
Fig 8: bottomNavigationBar
  • endDrawer
    A enddrawer is like a drawer property but in enddrawer by default the drawer is display at the right side of the screen.
  • primary
    Whether the scaffold is being displayed at the top of the screen. If true then the height of the appBar will be extended by the height of the screen’s status bar, i.e. the top padding for. The default value of this property is true.
Fig 9: Shows primary property of scaffold
  • backgroundColor
    This property sets the background color of the scaffold.
backgroundColor: Colors.white,
  • resizeToAvoidBottomInset
    If this property is true the body and the scaffold’s floating widgets should size themselves to avoid the onscreen keyboard whose height is defined by the bottom property.
    For example, if there is an onscreen keyboard displayed above the scaffold, the body can be resized to avoid overlapping the keyboard, which prevents widgets inside the body from being obscured by the keyboard. Defaults to true.

So, this was all about the various properties of the Scaffold which just gives you an overview of Scaffold. The purpose was to get your familiar with different properties and their usage for more detailed on the Scaffold widget refer to the flutter documentation here.

And for any other documentation related query on flutter click here.
Also check the github repo for Scaffold.


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Dialog Using GetX in Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Machine Learning in Flutter

0

So, I know Machine Leaning is there in open and it has been there for quite long. It goes way back in the previous century when it was first coined and brought into existence, now you find it everywhere in daily life so important that your life is probably surrounded by it and you may even not know, consider your smartphones they are called “smart” for a particular reason and in today’s time they are “smartest” while getting even more n more from day to day, because they are learning about you from you itself the more you’re using it the more your smartphone gets to know you and all of that is just the machine with lines of code evolving with time like humans. It’s not just limited to smartphones, it’s extensive in technology.
 But talking about smartphones consisting of apps which makes your life easier on a daily basis, using Machine Learning is a smarter way to build apps and with Flutter building cross-platform apps have been fun for a while and what if you are able to build an intelligent app with fun using Flutter? Don’t worry we got you sorted and we got it from basics giving you an overview step-by-step which will help you build Flutter apps using Machine Learning.

Machine Learning Overview:

Field of study that gives computers the capability to learn without being explicitly programmed.

In a laymen language, one must define Machine Learning as the scientific study of statistical models and algorithms that a computer uses to effectively perform specific tasks without having to provide explicit instructions. It is an application of Artificial Intelligence that enables a system to learn and improvise through experience, where a system can collect the data and learn from it.

What does learning mean to a Computer?

A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E.

For example: Take an example of playing chess 
Here, 
E = the experience gained from playing chess 
T = the task of playing chess
P = probability of winning the next game

Examples of implementation of machine learning in real life:

You know the general practice to understand something or making someone understand a thing is always try exploring its real-time use in your life. So, following that practice lets us consider some real-life scenarios where one come across Machine Learning in day to day basis.

1. Google photos, we guess everyone is aware of this app on your phone made and maintained by Google, one special and an excellent feature that it practice is the use of machine learnings Face Recognition algorithm in its app. It helps to recognize the people in your photos based on their facial identification. Never encountered it? Head over to the Photos app and experience it yourself.

2. Google Lens, released in the second half of 2017, this Google app helps image recognition in real time, just hover your camera to an image or ask google assistant to scan an image using this app to get insightful information extracted from the image. Be it taking an action in the text like saving the contact, fetching the e-mail ID or finding a dress you like in the image over the web or exploring the places nearby or identify plants and animals. This app makes you explore smartly giving you the futuristic feel and all of this is possible because of one thing i.e. Machine Learning.

3. Shopping Online, This is another most come practiced implementation of Machine Learning. Did you ever notice that when you’re trying to buy a product from an online platform frequently but you didn’t buy it somehow be it because of any reason then your social media like Facebook, your webpages or even the shopping store start recommending you that particular product? This is all possible not because of some human being sitting on a desk and pushing you these adverts NO, in fact, this is Machine Learning algorithms that does it.

4. Medical Enhancements, Yes!, Machine Learning plays a crucial role in the medical field too. Nowadays, the detection of various disease is done just by looking at the slide(cell image) and all of this is performed by machines using the model’s scientists have developed, for something which humans would take a significant amount of time.

And frankly speaking this list of examples is quite long, just imagine anything that learns from its past experience and grows in time.

Firebase and Machine Learning:

So, that was just an overview of Machine Learning giving you a brief about What is Machine Learning? and Where do you come across it in a day to day activity? Well, don’t worry we didn’t lose the track of our objective here which by the way is to get familiar with Machine Learning in Flutter. Heading forward with our objective the next topic to explore is about Firebase. We will start with why we have to explore Firebase here.

Firebase is Google’s mobile and web app development platform that provides developers with a plethora of tools and services to help them develop high-quality apps usually by providing a backend to the app. Most developers use it to create a database to their apps as it helps build apps faster without having to take care of the managing infrastructure.
 We will be using firebase because of Firebase ML kit which is a mobile SDK that brings Google’s machine learning expertise to Android and iOS apps in a powerful yet easy-to-use package. Whether you’re new or experienced in machine learning, you can implement the functionality you need in just a few lines of code. There’s no need to have deep knowledge of neural networks or model optimization to get started. On the other hand, if you are an experienced ML developer, ML Kit provides convenient APIs that help you use your custom TensorFlow Lite models in your mobile apps.

Main highlights of Firebase ML kit:

1. Production ready:
 Firebase ML Kit comes with a set of ready to use APIs such as Image recognition, Text recognition, face detection, land identification, barcode scanning, image labeling, and language identification. You just have to use the libraries and it feeds you with the information you need.

2. Importing Custom Model:
 Suppose you have your own models of ML that you have made in Tensor Flow, don’t worry Firebase got you all covered making it easy for you by letting you import your Tensor flow lite models, just upload your models in firebase and firebase will take care of hosting and serving it to you. Firebase acts as the API layer to your custom model.

3. Cloud or On-device:
 Whether you want to use it for cloud services or on-device, firebase ML kit works smoothly, securely and efficiently everywhere. Their APIs works both on the cloud and as well as on-device. On-device it even works when there are network issues while on-cloud it is powered by Google’s cloud platform machine learning technology.

Work Methodology:

So, you must be wondering how does all of this even works and if that is the case trust us, we were in the same position as you are right now until the moment we started to dig and it came out all as easy as pie, ML kit implements Google’s Machine Learning Technology, such as Google Cloud Vision API, TensorFlow lite and Android Neural Network API in a single SDK. Now just imagine the power of all these technologies under one hood; whether you want to hold the power of cloud processing or be it the real-time potential of mobile-optimized models or even your custom models, all of it is just handled in few lines of code.

Implementation:

The path of implementation includes just three steps, yes! just three:

1. SDK integration:
 Integrate the SDK using gradle.

2. Prepare input data:
 Let us explain it with an example, if you’re using a vision feature, capture an image from the camera and generate the necessary metadata such as image rotation, or prompt the user to select a photo from their gallery.

3. Apply the ML model to your data:
 Using the ML model to your data, you can generate a wide spectrum of insights such as the emotional state of detected faces or the objects and concepts that were recognized in the image, depending on the feature you used. Then you can implement these insights to power features in your app like photo embellishment, automatic metadata generation.

Various ready-to-use APIs:

  1. Text Recognition:
     By using ML Kit’s text recognition API you can identify text in any Latin-based languages which in general sense means almost all languages. It can maneuver the tedious data by itself and by using the cloud-based API you can even extract text from the picture of documents and also apps can track real-time objects.

2. Face Detection:
 By using ML Kit’s face detection API you can detect faces from an image and identify their key facial features like locate eyes, nose, ears, cheeks, mouth and even get contours of the detected faces. The information collected through this API can help embellish your selfies like when you want to add beauty to your face in real-time and help capture portraits in portrait mode. It helps perform face detection in real-time so you can use it to generate emojis or add filters in a video call or snap.

3. Barcode scanning:
 By using ML Kit’s barcode scanning API you can scan the barcodes to get the encoded data. Barcodes are a convenient way to pass information of the real world to your app. It can encode structured data such as Wi-Fi credentials or contact information.

4. Image Labeling:
 By using ML kit’s image labeling API you can recognize various entities in an image without having to provide any additional metadata from your side either using on-device or cloud-based API. Basically, image labeling gives you an insight about the content in your image. When you use this API you get the list of entities that were recognized such as people, places, activities and more. Each label comes with a score that mentions the confidence level of the ML model on its observation.

5. Landmark Recognition:
 By using landmark recognition API you can recognize the popular landmarks in the image provided to the API by you. After passing the image to it, you get the landmarks that were recognized in the image, along with the coordinates and the place where the landmark is located.

6. Language Identification:
 By using language identification API you can determine the language from the given text. This is helpful when working with user-provided text where the information about the language isn’t provided.

Integrating Machine Learning Kit in Flutter:

Phewww! That was a lot of background knowledge but NO that was not to just to spam it with words, in fact, all of that was to give you an overview of Machine Learning and Firebase’s ML Kit and if you were already aware of them then you know how crucial it was to know before moving any further.
 But finally, we’re at the part where we integrate Firebase’s ML Kit with Flutter and its just a piece of cake now onwards.

1. Installing plugins:
 
The basic requirement is to install a Flutter’s ML vision plugin which has been built by the flutter dev team itself and to explore more from them click here. You can use a couple of more plugins depending on your requirement like if you gonna use the Image identification then use image picker plugin which makes you choose either from clicking an image using a camera or get an image from the gallery.

2. Setup the firebase project:
 
If you are already know how to setup a firebase project then you are good to go for this step and if you aren’t aware of it then below is a video which will help you setup a firebase project using Firebase’s Cloud Firestore over Firebase Real-Time database.

To know about Cloud Firestore, watch

Now, you’re done and good to go with the fundamental requirements and knowledge required to use Machine Learning in Flutter. You can use the various APIs that are available with Firebase ML Kit to get your work done. On this blog, we won’t be discussing the codelab for Machine Learning but we’ll be bringing a codelab in our next blog so stay tuned. This blog was to give you an overview of Machine Learning, Firebase ML Kit and Flutter integration.

From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.


Related: SMS Using Twilio In Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.

Know Your Widgets: Row and Column in Flutter

0

So, the next widget in our series is not just a single widget, in fact, we would be covering two different widgets in this blog, namely Row and Column. The reason behind integrating two widgets together is the fact these two widgets have similar properties which will help you understand them efficiently.

So, by now you must be familiar with what flutter is and what widgets are. We know everything in Flutter is a widget that means everything you see on a screen is a widget in a Flutter and flutter have lots of widgets, widgets for almost every functionality you wanna put it, if you head over to flutter widgets at flutter.dev you will find a whole list of widgets.

Similarly, Row and Column are also widgets in Flutter and mostly every layout can be broken down in row and column, it’s that important. So let’s explore them individually …

Row

Let’s suppose you want to display a number of widgets in a horizontal manner on the screen, like a Text and an Image and we’re pretty sure you will find this minute requirement everywhere in a layout. That’s where Row widget comes in use, which displays the widgets in a horizontal manner.

A row is a multi-child layout widget which takes in a list of widgets as its children. A row displays the widgets within the visible view i.e. it doesn’t scroll. Use ListView widget to create a scrollable list of widgets, we’ll discuss this widget further in the series.
 For now, consider this code snippet which contains Row widgets containing Text widget wrapped in Flexible widget and a FlutterLogo widget.

This code will display a text and flutter logo in a row as shown in the pic below.

Note: Flexible widget is used to wrap the text because if the content of the row is wider than the row itself, then the row is said to have overflowed. When a row overflows, the row does not have any remaining space to share between its children and the row reports this by drawing a yellow and black striped warning box on the edge that is overflowing. Refer to the code snippet and the output below for the overview of the issue and importance of Flexible or Expanded.
 We will talk about the Flexible and Expanded widgets in other blogs, for now just understand its use.

Column

Now, we know that to lay the widgets in a horizontal manner we can use a Row widget but what to do when you have to lay the widgets in a vertical manner, that’s where Column widget comes in play.

Column widget alike row is a multi-child layout widget which takes in a list of widgets as its children.
 Consider this code snippet which contains a Column widgets containing two flutter logos and a text widget.

This code will display a Text between two Flutter logos as shown in the pic below,

Note: Here we didn’t have to wrap the children inside Column with either Flexible or Expanded widgets because for now the content of the children fit the column view perfectly but you might come across a situation where your content of the Column exceeds the amount of space available, in that case the Column overflows resulting in your content getting clipped and a warning is display in the form of yellow and black striped bar indicated at the overflowing edge with a message telling by how much your content has overflowed. Refer to the code snippet and the output below to get an overview of the overflow situation. One can use the Flexible or Expanded widgets to restrict the content to the visible view of the screen but if you want a scrollable vertical list of widgets then use a ListView instead of Column.

Properties of Row and Column

By now you must have a vivid overview of,

  1. What are Row and Column widgets?
  2. How to use Row and Column.
  3. When to use and when not to use?
  4. Basic problems faced with Row and Column
  5. And how to deal with it.

Now moving forward let’s look for their properties and see what functionality either of the widgets offers though Row and Column have the same set of properties but works in a slightly different manner. Let’s see those properties.

Row properties:

Here is the constructor of the row with some default values,

Column properties:

Here is the constructor of the column with default values,

It’s clear from the constructors that they have similar properties but their usage differs, so we’ll discuss each property by comparing their usage in both row and column.

mainAxisAlignment
Let’s first understand what mainAsix is, mainAxis is the longest side of row and column, for a row mainAxis is the horizontal side while for the column mainAxis is the Vertical side. 
This property positions children widgets along the main axis of the layout.

center
 
This positions the children as close to the middle of the main axis as possible.

end
 
This positions the children as close to the middle of the main axis as possible depending on the textDirection.

spaceAround
 
This distributes the free space evenly between the children and half of that free space is used before and after the first and last child respectively.

spaceBetween
 
This distributes the free space evenly between the children.

spaceEvenly
 This distributes the free space evenly between the children and before and after the first and last child respectively.

start
 This positions the children close to the start of the main axis depending on the textDirection.

mainAxisSize
 
This property directs how much space the children should occupy in the main axis. In the layout, after allocating spaces for the children there might be some free space. mainAxisSize tells whether to maximize or minimize the free space.

min
 
It minimizes the amount of free space along the main axis.

max
 
It maximizes the amount of free space along the main axis.

crossAxisAlignment
 
Let’s first understand what crossAxis is, crossAxis is the smallest side of row and column, for a row crossAxis is the vertical side while for the column crossAxis is the horizontal side. This property positions children widgets along the cross axis of the layout.

start
 
This positions the children start edge to the start side of the cross axis. For ex: if this is used in a column with the textDirection set to TextDirection.ltr, it aligns the left edge of the children to the left edge of the column.

end
This positions the children as close to the end of the cross axis.
For ex: if this is used in a column with the textDirection set to TextDirection.ltr, it aligns the right edge of the children to the right edge of the column.

center
This positions the children such that their center aligns to the middle of the cross axis. By default the value of crossAxisAlignment is center.

stretch
This lets the children to completely occupy to the cross axis.

baseline
This positions the children such that their baseline match.

textBaseline
It’s the horizontal line used for aligning the text.

textDirection
This property determines the order in which to lay the children horizontally.

rtl
It lays the children from right to left direction.

ltr
It lays the children from left to right direction.

verticalDirection
This property determines the order in which to lay the children vertically.

children
Both these widgets, Row and Column, takes a list of widgets as its children.

So, these were the properties that are included in Row and Column widget, the purpose was to give you an overview of Row and Column widget in the flutter, now it’s your time to explore them and get more familiar with the in-hand experience. remember, the basic rule that we are made familiar with right from childhood is If you don’t practice, you don’t learn. Implement these properties yourself and let us know if we made a mistake or left out something.

If you want to read more about row and column head over to the flutter docs of Row and Column.

From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Dark Mode Implementation

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.


Data Persistence with SQLite | Flutter

0

Whenever you need to store the data on the local then you need to use SQLite to persist the user data.

Why we use SQLite?

SQLite is a popular choice as embedded database software for local/client storage in application software such as web browsers.

How to use SQLite in a flutter?

Before using SQLite, you should know that

SQLite is not available in a flutter SDK like Android but we have a plugin sqflite that exactly performs all the operation on the database just like in Android and iOS.

Flutter plugin is the wrapper of the native code written in Kotlin or java for Android and swift or objective-c for iOS.
P.S : Plugin can also be created only with dart code

If you are new to SQLite, go through SQLite Tutorial site below

SQLite Tutorial – An Easy Way to Master SQLite Fast
This SQLite tutorial teaches you everything you need to know to start using SQLite effectively. You will learn SQLite…www.sqlitetutorial.net

Implementation

Step 1: Add the dependencies

Add dependencies to pubspec.yaml file .

  sqflite:
path_provider:

To work with SQLite databases, import the sqflite and path packages

  • The sqflite package provides classes and functions that allow you to interact with a SQLite database.
  • The path_provider package provides functions that allow you to correctly define the location to store the database on disk such as TemporaryDirectory and ApplicationDocumentsDirectory.

Step 2: Create a Model class

SQLite creates a table for the model class, the fields in the class correspond to columns in the table. Therefore, the classes tend to be small model classes that don’t contain any logic. Our Person class represents the model for the data in the database.

class Person {
int id;
String name;
String city;

Person({this.id, this.name, this.city});

}

If we want to insert into the database then we need to convert the Person into a Map

Map<String, dynamic> toMap() => {
"id": id,
"name": name,
"city": city,
};

and if we want to retrieve from the database then we need to convert the Map into the Person

factory Person.fromMap(Map<String, dynamic> json) => new Person(
id: json["id"],
name: json["name"],
city: json["city"],
);

This is how our PODO class will look like

https://gist.github.com/ashishrawat2911/d74ea7944b53f193832793c1fe5f54a9#file-person-dart

Step 3: Create a database

We will make a separate class as database.dart to make the code more modular and add all the requirements meths for managing the database that can be accessed anywhere in the app.

Create a class DatabaseProvider

class PersonDatabaseProvider{
DatabaseProvider._();

static final PersonDatabaseProvider db = PersonDatabaseProvider._();
}

Step 4: Open the Database

Before you read and write data to the database, you need to open a connection to the database. This involves two steps:

  1. Define the path to the database file using the getDatabasesPath from the sqflite package combined with the pathfunction from the path package
  2. Open the database with the openDatabase function from sqflite
Directory directory = await getApplicationDocumentsDirectory();

String path = join(directory.path, "person.db");

final Future<Database> database = openDatabase(path);

Step 5: Create the table

you need to create a table to store information. 
For example, In our case, we create a table called Person that defines the data that can be stored. In this case, each Person contains an id, name, and city. Therefore, these will be represented as three columns in the Person table.

  1. The id is a Dart int, and will be stored as an INTEGER SQLite Datatype. It is also good practice to use an id as the primary key for the table to improve query and update times.
  2. The name is a Dart String, and will be stored as a TEXT SQLite Datatype
  3. The city is also a Dart String, and will be stored as an TEXT Datatype

To prevent from opening a connection to the database again and again we can use this:

https://gist.github.com/ashishrawat2911/a59ab9ece9649d1de3dc9527b870c99b#file-createdatabase-dart

Step 6: Managing the data

Now we are going to show you how you can perform an operation on the SQLite database.

Query:

https://gist.github.com/ashishrawat2911/333a6b650568b9b59468a2e70e33175b#file-query-dart

getAllPersons() will return all the person from the SQLite database if available.

Insert:

https://gist.github.com/ashishrawat2911/2ed7bcdf77d253d4940bcf0681afbc6d#file-insert-dart

Delete:

https://gist.github.com/ashishrawat2911/5969e225083a5c8ff995618fdab95a01#file-delete-dart

If you see we have two methods, one deletes the row with particular id and other deletes all data present in the table, you can change all the query according to your need.

Update:

https://gist.github.com/ashishrawat2911/f25acd6599b120bfa3e1d68a58b4430d#file-update-dart

If these small code snippets still confuse you we have the complete code of the database class:

https://gist.github.com/ashishrawat2911/16c4d20501f8bec519b914ee6e49480d#file-database-dart

Step 7: Using the data

In order to use the database we need to create the instance of the database and use the method present in the database class

DatabaseProvider.db

This will help us to perform an operation on the database.

like if we want to get the person in the database we will use the method that we have defined in our DatabaseProvider class

DatabaseProvider.db.getAllPersons()

and if I want to display it in the list then I’ll use FututeBuilder :

https://gist.github.com/ashishrawat2911/fdf814c9638976a57d440329a318257f#file-bodysql-dart


we have also linked a repo if you need to see the example of SQLite.

ashishrawat2911/flutter_sqlite
Contribute to ashishrawat2911/flutter_sqlite development by creating an account on GitHub.github.com

That it for SQLite in flutter.

Thanks for reading this article ❤

If I got something wrong? Let me know in the comments. I would love to improve.

Clap 👏 If this article helps you.

Connect with me on Linkedin and Github


From Our Parent Company Aeologic

Aeologic Technologies is a leading AI-driven digital transformation company in India, helping businesses unlock growth with AI automation, IoT solutions, and custom web & mobile app development. We also specialize in AIDC solutions and technical manpower augmentation, offering end-to-end support from strategy and design to deployment and optimization.

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.

Feel free to connect with us:
And read more articles from FlutterDevs.com.

FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! You can connect with us on FacebookGitHubTwitter, and LinkedIn for any flutter-related queries.

We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.

Related: Explore Precache Images In Flutter

Need expert help building your Flutter app? Talk to FlutterExperts for architecture, development, and consulting support.