Google search engine
Home Blog Page 61

FractionallySizedBox In Flutter

0

In Flutter, when users need to the size of a widget relative to available space. For example, a user wants to set buttons width as 70% of the parent widget users or we have a Container that takes half of the available space Vertically, and Horizontally Fractionally Sized Box Widget is used. This article has a model that discloses why you need to do to use a fractionally sized box that can be used anyplace around the screen as long as it’s inside the parent widget.

In this article, we will explore the Fractionally Sized Box Widget In Flutter. We will see how to implement a demo program on FractionallySizedBox and show how to create it in your flutter applications.


Table Of Contents::

Introduction

Properties

Code Implement

Code File

Conclusion

GitHub Link


Introduction:

FractionallySizedBox Widget is a widget that sizes its child to a fraction of the total available space. To make it easy to understand how FractionallySizedBox works, for example, there is a container with a size of 200 x 100. Inside, there is a Raised button and we are going to set the size of the button relative to the size of the container.

Demo:


Properties :

There are some properties of the FractionallySizedBox Widget:

  • Key: The widget key, used to control if it’s should be replaced.
  • AligntmentGeometry alignment: How the child is aligned. Defaults to Alignment. center.
  • double widthFactor: Width fraction that will be applied to a child.
  • double heightFactor: Height fraction that will be applied to a child.
  • widget child: A widget that will be rendered whose size depends on widthFactor and heightFactor.

Code Implement:

How to implement code in dart file :

Create a new dart file called home_page.dart inside the lib folder.

In the body, we will add a Column widget with their children. Then, we will add the constructor of FractionallySizedBox which wraps the widget inside the column widget. The FractionallySizedBox needs to be wrapped in a Flexible widget, “so it plays well with a row or a column”.

Container(
height: 24.0,
color: Colors.black,
child: Column(
children: [
Flexible(
child: FractionallySizedBox(
heightFactor: 1, widthFactor: 0.25,
child: Container(color: Colors.orange),
),
),
Fexible(
child: FractionallySizedBox(
heightFactor: 1, widthFactor: 0.15,
child: Container(color: Colors.green)),
),
Fexible(
child: FractionallySizedBox(
heightFactor: 1, widthFactor: 0.05,
child: Container(color: Colors.blue)
),
),
]
)
)

The below example sets the Container width to 50% of the parent container’s width. Since the heightFactor is not set, it uses the height constraint from its parent.

Container(
height: 200,
width: 300,
color: Colors.indigo,
child: FractionallySizedBox(
widthFactor: 0.5,
child: Container(
alignment: Alignment.center,
color: Colors.red,
child:
_buildTextWidget(text: "Demo Project", color: Colors.white),
),
),
),

The below example sets the button’s height to 75% of the container’s height. Since the widthFactor is not set, it uses the width constraint from its parent.

Container(
height: 100,
width: 180,
color: Colors.purpleAccent,
child: FractionallySizedBox(
heightFactor: 0.75,
child: RaisedButton(
color: Colors.white,
child: _buildTextWidget(text: 'Click', color: Colors.red),
onPressed: () {},
),
),
),

The below example describes how we can set the height and width of the containers wrapped in a row widget using FractionallySizedBox. It’s really important if we use FractinallySizedBox widget in row or column must be wrapped in flexible widget. Here, I try to explain to you that we can set the height and width of containers using different heightFactor and widthFactor.

Container(
height: 220,
width: double.infinity,
color: Colors.yellowAccent,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Flexible(
child: FractionallySizedBox(
heightFactor: 1,
widthFactor: 1,
child: Container(color: Colors.orange),
),
),
Flexible(
child: FractionallySizedBox(
heightFactor: 0.7,
widthFactor: 0.7,
child: Container(color: Colors.green)),
),
Flexible(
child: FractionallySizedBox(
heightFactor: 0.4,
widthFactor: 0.4,
child: Container(color: Colors.blue)),
),
]),
),

By Default, the Child is aligned at a Center. To change the position of the child wrapped in FractionallySizedBox we use alignment Property. Consider a code snippet as below:

Container(
height: 100,
width: 180,
color: Colors.purpleAccent,
child: FractionallySizedBox(
heightFactor: 0.6,
widthFactor: 0.5,
alignment: Alignment.bottomRight,
child: RaisedButton(
color: Colors.white,
child: _buildTextWidget(text: 'Click', color: Colors.red),
onPressed: () {},
),
),
),

Code File:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white54,
appBar: AppBar(
title: Text('Fractionally Sized Box'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 200,
width: 300,
color: Colors.indigo,
child: FractionallySizedBox(
widthFactor: 0.5,
child: Container(
alignment: Alignment.center,
color: Colors.red,
child:
_buildTextWidget(text: "Demo Project", color: Colors.white),
),
),
),
Flexible(
child: FractionallySizedBox(
heightFactor: 1,
widthFactor: 1,
child: Container(
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Flexible(
child: FractionallySizedBox(
widthFactor: 0.08,
child: _buildTextWidget(
text: 'Fractional', color: Colors.deepOrangeAccent),
)),
Flexible(
child: FractionallySizedBox(
widthFactor: 0.05,
child: _buildTextWidget(
text: 'Sized', color: Colors.indigoAccent),
)),
Flexible(
child: FractionallySizedBox(
widthFactor: 0.05,
child: _buildTextWidget(text: 'Box', color: Colors.black),
)),
],
),
),
),
),
Container(
height: 220,
width: double.infinity,
color: Colors.yellowAccent,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Flexible(
child: FractionallySizedBox(
heightFactor: 1,
widthFactor: 1,
child: Container(color: Colors.orange),
),
),
Flexible(
child: FractionallySizedBox(
heightFactor: 0.7,
widthFactor: 0.7,
child: Container(color: Colors.green)),
),
Flexible(
child: FractionallySizedBox(
heightFactor: 0.4,
widthFactor: 0.4,
child: Container(color: Colors.blue)),
),
]),
),
Container(
height: 100,
width: 180,
color: Colors.purpleAccent,
child: FractionallySizedBox(
heightFactor: 0.6,
widthFactor: 0.5,
alignment: Alignment.bottomRight,
child: RaisedButton(
color: Colors.white,
child: _buildTextWidget(text: 'Click', color: Colors.red),
onPressed: () {},
),
),
),
],
),
);
}

_buildTextWidget({
required String text,
required Color color,
}) {
return Text(
text,
style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 20),
);
}
}

Conclusion:

In the article, I have explained the FractionallySizedBox Widget’s basic structure in a flutter; you can modify this code according to your choice. This was a small introduction to the FractionallySizedBox Widget On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information in Trying up the FractionallySizedBox Widget in your flutter projects. We will show you what the FractionallySizedBox Widget is?. Some FractionallySizedBox widget properties, make a demo program for working FractionallySizedBox Widget. So please try 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.


GitHub Link:

find the source code of the FractionallySizedBox :

GitHub – flutter-devs/fractionallysizedbox
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…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 Facebook, GitHub, Twitter, 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.


Material Banner In Flutter

0

Google, the search giant recently rolled out the new stable version of its Extensive Popular Cross-Platform UI Framework Flutter. Flutter 2.5 is out with 4600 closed issues and 3932 merged PRs. Flutter is release proceeds with a few significant performance and tooling improvements to find performance issues in your application.

MaterialBanner support to the ScaffoldMessenger. You may remember the ScaffoldMessenger from the Flutter 2.0 release announcement as a more robust way to show Snackbar at the bottom of the screen to provide users with notifications. In Flutter 2.5, you can now add a banner to the top of your scaffold that stays in place until the user dismisses it.

In this article, we will explore How to show a banner at the top of a screen in Flutter Applications. We will also implement a demo program that helps you to understand.


Table Of Contents::

Introduction

Properties

Code Implement

Code File

Conclusion

GitHub Link


Introduction:

The banner should be displayed at the top of the screen, below a top app bar. They’re persistent and nonmodal, allowing the user to either ignore them or interact with them at any time. Only one banner should be shown at a time.

A Material Design banner is a banner that displays an important, sufficient message, and provides actions for users to address (or dismiss the banner). A user action is required for it to be dismissed.

Demo:

Properties:

  • content: This property takes in a Text Widget as the object to show messages to the users in the banner.
  • leading: Show an image logo or Icons about the banner information eg: info, warning, success.
  • backgroundColor: Gives color to Material Banner.
  • actions(mandatory): It accepts an array of the widget when the user can interact to perform some event.
  • padding: The amount of space by which to insert the content.
  • forceActionBelow: If this is true, the actions will be placed below the content. If this is false, the actions will be placed on the trailing side of the content if the actions’ length is 1 and below the content if greater than 1.
  • contentTextStyle: This property is responsible for the styling of content text in the Material Banner widget. It takes in TexStyle class as the object.

Code Implement:

How to implement code in dart file :

If your flutter version is not upgraded first you need to update the flutter version, To update your flutter SDK version to 2.5 you just need to run a command on a Command Prompt or IDE Terminal.

flutter upgrade

Create a new dart file called home_screen.dart inside the lib folder to design the user interface and make sure we need to create a StatefulWidget.

class HomeScreen extends StatefulWidget {
HomeScreen({Key? key, required this.title}) : super(key: key);

final String title;

@override
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
//Write your code inside...
}

In the body, I wrap the Elevated button and Text widget inside the column widget, and Material Banner is shown on the click event of the button. When the elevated button is pressed user defines method _showMaterialBanner is called which returns MaterialBanner.

MaterialBanner _showMaterialBanner(BuildContext context) {
return MaterialBanner(
//Write your code to design material banner)

Your app can get this behavior by calling the showMaterialBanner method of ScaffoldMessanger. The SnackBar API within the Scaffold is also handled by the ScaffoldMessanger, one of which is available by default within the context of a MaterialApp.

ElevatedButton(
child: const Text('Show MaterialBanner'),
onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner(
//Wrap MaterialBanner Widget inside.);

The Flutter Material Banner according to its guidelines, The state of Banner should show only once to the user. If showMaterialBanner is called more than one time, then ScaffordMessenger will maintain a queue for the next banner to be shown.

Therefore when the previous banner(current active banner) is dismissed then-new banner that is in the queue will be shown. To do that we just need to call ..removeCurrentMaterialBanner() before invoking the new Material Banner in a flutter.

 ScaffoldMessenger.of(context)
..removeCurrentMaterialBanner()
..showMaterialBanner(_showMaterialBanner(context));

In MaterialBanner we can add content, leading, background colors, padding, and actions and you can also style the content using property contentTextStyle. MaterialBanner comes with multiple properties

In order to add content with style to the material banner, we need to do

content: Text('Hello, I am a Material Banner'),
contentTextStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.indigo),

In order to add Background color to the material banner, we need to do

backgroundColor: Colors.lightGreenAccent,

In order to add Icon at the leading position to material banner, we need to write

leading: Icon(Icons.error),

The set of actions that are displayed at the bottom or trailing side of the MaterialBanner. It accepts an array of the widget when the user can interact to perform some event.

actions: [
TextButton(
onPressed: () {},
child: Text(
'Agree',
style: TextStyle(color: Colors.purple),
),
),
TextButton(
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
},
child: Text(
'Cancel',
style: TextStyle(color: Colors.purple),
),
),
]

Code File:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HomeScreen extends StatefulWidget {
HomeScreen({Key? key, required this.title}) : super(key: key);

final String title;

@override
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> { MaterialBanner _showMaterialBanner(BuildContext context) {
return MaterialBanner(
content: Text('Hello, I am a Material Banner'),
leading: Icon(Icons.error),
padding: EdgeInsets.all(15),
backgroundColor: Colors.lightGreenAccent,
contentTextStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.indigo),
actions: [
TextButton(
onPressed: () {},
child: Text(
'Agree',
style: TextStyle(color: Colors.purple),
),
),
TextButton(
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
},
child: Text(
'Cancel',
style: TextStyle(color: Colors.purple),
),
),
]);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button to see MaterialBanner:',
style:
TextStyle(color: Colors.indigo, fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context)
..removeCurrentMaterialBanner()
..showMaterialBanner(_showMaterialBanner(context));
},
child: Text(
'Click Here',
style: TextStyle(color: Colors.purple),
),
style: ElevatedButton.styleFrom(
primary: Colors.lightGreenAccent,
),
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

Conclusion:

In the article, I have explained the MaterialBanner Widget basic structure in a flutter; you can modify this code according to your choice. This was a small introduction to MaterialBanner Widget On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information on Trying up the MaterialBanner Widget in your flutter projects. We will show you what the MaterialBanner Widget is?. Some MaterialBanner widget properties, make a demo program for working MaterialBanner Widget. So please try 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.


GitHub Link:

find the source code of the MaterialBanner :

GitHub – flutter-devs/MaterialBanner
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…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 Facebook, GitHub, Twitter, 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.


Cupertino Picker In Flutter

0

If you are new to flutter then you would like to know about Cupertino. so I am introducing some summary of Cupertino.

Cupertino is a package that has all ios widgets. This package is designed for apps that run in iOS style and to make beautiful and high-fidelity widgets for the current iOS design.

  • Cupertino widgets respect platform differences and hence don’t support all features of Material widgets.
  • Using the Cupertino widgets is optional even when you’re building apps for only iOS devices.
  • Only some Cupertino widgets will work in a MaterialApp()/ Scaffold().

In this blog, we will explore the Cupertino Picker In the Flutter and its types. We will see how to implement a Cupertino Picker demo program and show how to create it in your flutter applications.


Table Contents:

Cupertino Picker

Cupertino Picker Types

Code Implementation

Conclusion

GitHub Link



Cupertino Picker:

Cupertino Picker is a simple dialog to show a list of items. Displays its children widgets on a wheel for selection and calls back when the currently selected item changes.

Domo module:


Cupertino Picker Types:

There are several modes of the picker listed here.

  • > Cupertino Picker
  • > Cupertino DatePicker
  • > Cupertino TimePicker

Code Implementation:

Let’s see How to implement the code

First I have created a screen with 3 buttons to show. Cupertino Picker, Cupertino DatePicker, and Cupertino TimePicker. Below is the code snippet.

Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.pinkAccent
),
child: Center(
child: Text("Cupertino Picker",
style: TextStyle(
color: Colors.white
),),
),
),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("Set Picker",
//textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black, ),),
),
],
),
), child: Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.blue
),
child: Center(
child: Text("Cupertino DatePicker",
style: TextStyle(
color: Colors.white
),),
),
),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("Set DatePicker",
style: TextStyle(
color: Colors.black
),),
),
],
),
), child: Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.orange
),
child: Center(
child: Text("Cupertino TimePicker",
style: TextStyle(
color: Colors.white
),),
),
),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("Set TimePicker",
style: TextStyle(
color: Colors.black
),),
),
],
),
),

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Home Screen

After that, I have created a method. In this method, I am fixing a container with height in the bottom and take a child widget SafeArea in which I am showing all the pickers. Below is the code snippet.

Widget _buildBottomPicker(Widget picker) {
return Container(
height: _kPickerSheetHeight,
padding: const EdgeInsets.only(top: 6.0),
color: CupertinoColors.white,
child: DefaultTextStyle(
style: const TextStyle(
color: CupertinoColors.black,
fontSize: 22.0,
),
child: GestureDetector(
// Blocks taps from propagating to the modal sheet and popping.
onTap: () {},
child: SafeArea(
top: false,
child: picker,
),
),
),
);
}

This first button is for the Cupertino picker. To click on this button I am open a Cupertino picker with the list of text items and set it on textview which I am selecting the item.

InkWell(
onTap: (){
showCupertinoModalPopup<void>(
context: context, builder: (BuildContext context){
return _buildBottomPicker(
_buildCupertinoPicker()
);
});
},
child: Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.pinkAccent
),
child: Center(
child: Text("Cupertino Picker",
style: TextStyle(
color: Colors.white
),),
),
),
// SizedBox(height: 30,),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("$selectItem",style: TextStyle(
color: Colors.black,),),
),
],
),
),

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Cupertino Picker

This second button is for the Cupertino Date picker. To click on this button I am showing a Cupertino Date picker with the list of dates and set it on textview which I am selecting the date.

InkWell(
onTap: (){
showCupertinoModalPopup<void>(
context: context, builder: (BuildContext context){
return _buildBottomPicker(
_buildDateTimePicker()
);
});
},
child: Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.blue
),
child: Center(
child: Text("Cupertino Date Picker",
style: TextStyle(
color: Colors.white
),),
),
),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("$dateTime",
style: TextStyle(
color: Colors.black
),),
),
],
),
),

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Cupertino Date Picker

This third button is for the Cupertino Time picker. To click on this button I am showing a Cupertino Time picker with the list of times and set it on textview which I am selecting the time.

InkWell(
onTap: (){
showCupertinoModalPopup<void>(
context: context, builder: (BuildContext context){
return _buildBottomPicker(
timePicker()
);
});
},
child: Column(
children: [
Container(
height: 50,
width:MediaQuery.of(context).size.width ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.orange
),
child: Center(
child: Text("Cupertino Time Picker",
style: TextStyle(
color: Colors.white
),),
),
),
Container(
padding: EdgeInsets.only(top: 8,bottom: 8),
child: Text("$time",
style: TextStyle(
color: Colors.black
),),
),
],
),
),

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Cupertino Time Picker

Conclusion:

In this article, I have explained the basic overview of the Cupertino Picker Widget in a flutter, you can modify this code according to your choice. This was a small introduction to Cupertino Picker Widget On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information on Trying up the Explore, Cupertino Picker Widget in your flutter projects.

❤ ❤ 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.

GitHub Link:

find the source code of the Flutter Cupertino Picker Demo:

GitHub – flutter-devs/cupertino_picker_demo_app
Contribute to flutter-devs/cupertino_picker_demo_app development by creating an account on GitHub.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 Facebook, GitHub, Twitter, 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.

Flutter 2.0 Button Cheat Sheet

0

People who were used to the old ways of using buttons had been left with a new way to implement a button which was a bit confusing at the start, the change of the names and many parameters led to confusion, and people had to google multiple times, what previously had been written on the back of their hand.

So, to end the confusion once and for all and provide people with a way to easily use the new buttons, I’ve decided to write this Blog.



With the introduction of 2.0 the names of the buttons were changed:

a) FlatButton — The previously used FlatButton is now known as TextButton and uses the theme of TextButtonTheme.

b) RaisedButton — The previously used RaisedButton is now known as ElevatedButton and uses the theme of ElevatedButtonTheme.

c) OutlineButton — The previously used OutlineButton is now known as OutlinedButton(a pretty small change in name here) and uses the OutlinedButtonTheme.

NOTE: If your old project needs to migrate to the new way of using the button then it’s best to consult a migration guide for which more information can be found here.

Now, the API Changes on how to use these new buttons

A new object called ButtonStyle is introduced, just like how you can configure a Text widget with TextStyle, you can now configure the buttons using the new ButtonStyle widget

An example of using the new way:

TextButton(
onPressed: (){},
child: Text('Hello'),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Colors.transparent),
overlayColor: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return Colors.red;
else if (states.contains(MaterialState.focused))
return Colors.green;
else if(states.contains(MaterialState.selected))
return Colors.blue;
else
return
Colors.black;
},
),
),

),

The MaterialStateProperty<Color> returns the value of the color you specify, in the forgroundColor we have given MaterialStateProperty.all and specified the name of the color there, if you leave it as null then it will take the widget’s default on its own.

However, there is another way to provide styling to a button, it’s called styleFrom, instead of specifying ButtonStyle, you can use <The name of the button>.styleFrom() like ElevatedButton.styleFrom().

An example of it would be :

TextButton(
onPressed: (){},
child: Text('Hello'),
style: TextButton.styleFrom()
),

Inside it, you can specify all the other properties like padding and color, etc.


Now, moving on we will be discussing how some of the new properties work.

Padding — the new way of providing padding with ButtonStyle is :

style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(EdgeInsets.zero)
),

The styleFrom method for the same would be:

style: TextButton.styleFrom(
padding: EdgeInsets.zero
)

Shape — the new way of providing shape with ButtonStyle is

style: ButtonStyle(
shape: MaterialStateProperty.all<
OutlinedBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(50),
side: BorderSide(color: Colors.red),
),
),
),

The styleFrom method for the same would be:

style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(50),
side: BorderSide(color: Colors.red),
),
)

Side — the new way of providing border side with Buttonstyle is:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: ButtonStyle(
side: MaterialStateProperty.all<BorderSide>(BorderSide(
color: Colors.red
))
),
),

The styleFrom method for the same is:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.red
)
),
),

Alignment — the new way of providing alignment is quite simple(with ButtonStyle):

TextButton(
onPressed: () {},
child: Text('Hello'),
style: ButtonStyle(
alignment: Alignment.center,
),
),

The styleFrom method for it is the same:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: TextButton.styleFrom(
alignment: Alignment.center,
),
),

Elevation — the new way to provide elevation with ButtonStyle is:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: ButtonStyle(
elevation: MaterialStateProperty.all<double>(1.0)
),
),

The styleFrom method for the same is:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: TextButton.styleFrom(
alignment: Alignment.center,
elevation: 1.0
),
),

TextStyle — you can provide textstyle in ButtonStyle this way:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: ButtonStyle(
textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(
color: Colors.red
)),

),
),

FixedSize — you can change the fixedStyle property of ButtonStyle this way:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: ButtonStyle(
fixedSize: MaterialStateProperty.all<Size>(Size(200,300))

),
),

The styleFrom method for the same is:

TextButton(
onPressed: () {},
child: Text('Hello'),
style: TextButton.styleFrom(
fixedSize: Size.fromHeight(150)

),
),

Conclusion:

In the article, I have explained the common properties of Button styling in a flutter; you can modify this code according to your choice. This was a small introduction to the Flutter 2.0 Button cheat sheet On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information on Trying up the Flutter 2.0 Button cheat sheet in your flutter projects. We will show you all properties in detail. In this blog, we have examined the Flutter 2.0 Button. I hope this blog will help you in the comprehension of the Flutter 2.0 Button in a better way. So please try 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.


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 Facebook, GitHub, Twitter, 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.


Flutter App for Desktop

0

In Flutter every component on a screen of the Flutter application is a widget. The screen’s perspective entirely relies on the choice and grouping of the widgets used to build the application. Also, the structure of the code of an application is a tree of widgets.

In this blog, we will understand how to run the flutter application on the desktop and what is the requirement to set up this?. We will see the step-by-step flow and create an app for understanding the Desktop app building process.


Table Contents:

Flutter

Flutter benefits

Flutter platform-specific criteria

Set Up for run application on desktop

Implementation

Conclusion

GitHub Link


Flutter :

“ Flutter is Google’s UI toolkit that helps you build beautiful and natively combined applications for mobile, web, and desktop in a single codebase in record time

It is free and open-source. It was at first evolved from Google and is presently overseen by an ECMA standard. Flutter applications utilize the Dart programming language for making an application. The dart programming shares a few same highlights as other programming dialects, like Kotlin and Swift, and can be trans-arranged into JavaScript code.

Flutter benefits:

Flutter provides us to run the application on multiple platforms. like, Web, Desktop, Android / iOS. There are many languages in the market that run the application on multiple platforms. but flutter takes less time to run the application on different platforms as compared to other languages. because flutter does not use the mediator bridge to run the application as other languages do. So flutter is fast to run the application on different platforms. here is some key point below

  • Same UI and Business Logic in All Platforms.
  • Reduced Code and Development Time.
  • Similar to Native App Performance.
  • Custom, Animated UI is Available for any complex widget.
  • Own Rendering graphic Engine i.e. skia.
  • Simple Platform-Specific Logic Implementation.
  • The Potential Ability to Go Beyond Mobile.

Flutter platform-specific criteria:

  • Android Platform Specific
  • iOS Platform Specific
  • Web Platform Specific
  • Desktop Platform Specific

Set Up for run application on Desktop Platform Specific:

  1. First, you create your flutter project.

2- And then switch your channel to the Beta Flutter channel. because it covers desktop support Which is available in Beta release and for switching channels into beta using this command.

  • > flutter channel beta

Go to the flutter documentation and click on the window setup option and read the documentation.

https://flutter.dev/docs/get-started/install/windows#windows-setup

3- And then Enable your window using this command.

  • > flutter config — enable-windows-desktop

Check below documentation

https://flutter.dev/docs/get-started/install/windows#windows-setup

5- After enabling your window restart your Android studio.

6- After restarting android studio And now create windows support directory using the below command.

  • > flutter create.

7- Now install visual studio go to this link.

Download Visual Studio Tools – Install Free for Windows, Mac, Linux
Full-featured integrated development environment (IDE) for Android, iOS, Windows, web, and cloud Powerful IDE, free for…visualstudio.microsoft.com

8- After visual studio installation finally you can run your app for desktop. Select the Desktop device in your android studio and run the application.

Implementation:

Now I am designing a page for testing on the Desktop. You can make any app for a run on the desktop. I am showing only the last page code implementation of this app here is the code snippet. If you want to look full code then go to the Github link given below.

On this page, I am designing a courses list card with images and text for purchase courses list.

import 'package:e_learning_app/constants/constants.dart';
import 'package:e_learning_app/model/Courses_items_model.dart';
import 'package:e_learning_app/model/read_blog_model.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:io' show Platform;

class ReadScreenView extends StatefulWidget {
const ReadScreenView({Key? key}) : super(key: key);

@override
_ReadScreenViewState createState() => _ReadScreenViewState();
}

class _ReadScreenViewState extends State<ReadScreenView> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: _buildBody(),
);
}

Widget _buildBody() {
return Container(
height: MediaQuery.of(context).size.height,
child: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
//color: Colors.cyan,
child: Container(
margin: EdgeInsets.only(bottom: 350),
height: 250,
decoration: BoxDecoration(
color: Color(0xffff9b57),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap:(){
Navigator.pop(context);
},
child: Container(
//margin: EdgeInsets.only(right: 25,top: 10),
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xfff3ac7c),
),
child: Icon(
Icons.arrow_back,
color: Colors.white,
size: 20,
),
),
),
Container(
// margin: EdgeInsets.only(right: 25,top: 10),
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xfff3ac7c),
),
child: Icon(
Icons.menu,
color: Colors.white,
size: 20,
),
),
])),
Container(
padding: EdgeInsets.only(left: 20, right: 20, top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
"Purchase Courses",
style: TextStyle(
color: Colors.white,
fontSize: 20,
//fontWeight: FontWeight.bold
),
),
),
SizedBox(
height: 5,
),
Container(
child: Text(
"Categories",
style: TextStyle(
color: Colors.white,
fontSize: 12,
//fontWeight: FontWeight.bold
),
),
),
],
),
),
Container(
padding: EdgeInsets.only(left: 20, top: 16),
height: 140,
alignment: Alignment.center,
//color: Colors.orange,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: readBlogList.length,
itemBuilder: (BuildContext context, int index) {
return _buildCategorySection(readBlogList[index]);
}),
),
],
),
),
),
Positioned(
top: 260,
left: 0,
right: 0,
bottom: 0,
child: SizedBox(
height: MediaQuery.of(context).size.height - 260,
width: MediaQuery.of(context).size.width,
child: Container(
//color: Colors.yellow,
padding: EdgeInsets.only(left: 4, right: 4),
width: MediaQuery.of(context).size.width,
child: ListView.builder(
//physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: readBlogList.length,
itemBuilder: (BuildContext context, int index) {
return _buildPurchaseCourses(readBlogList[index]);
}),
),
),
),
Positioned(
bottom: 0,
child: Container(
padding:
EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
height: 70,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Purchase Courses",
style: TextStyle(
color: Colors.black,
fontSize: 14,
//fontWeight: FontWeight.bold
),
),
Text(
"5",
style: TextStyle(
color: Colors.red,
fontSize: 20,
//fontWeight: FontWeight.bold
),
),
],
),
Container(
height: 40,
width: 130,
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xffdc4651)),
child: Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Category",
style: TextStyle(color: Colors.white),
),
Icon(Icons.arrow_drop_down, color: Colors.white)
],
),
),
)
],
),
),
),
],
),
);
}

Widget _buildCategorySection(ReadBlogModel readBlogList) {
return Container(
height: 50,
width: 110,
child: Card(
color: Colors.white,
child: Column(
//mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 90,
child: ClipRRect(
borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)),
child: Image.network(
readBlogList.image!,
fit: BoxFit.fill,
height: 50,
width: 110,
),
)),
Container(
padding: EdgeInsets.all(5),
child: Text(
"Categories",
style: TextStyle(
color: Colors.black,
fontSize: 12,
//fontWeight: FontWeight.bold
),
),
),
],
),
),
);
}

Widget _buildPurchaseCourses(ReadBlogModel readBlogList) {
return Container(
margin: EdgeInsets.only(left: 10, right: 10),
//padding: EdgeInsets.only(left: 10,right: 20),
height: 80,
child: Card(
child: Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
width: 40,
child: ClipRRect(
child: Image.network(
readBlogList.image!,
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(8),
),
),
//SizedBox(width: 20,),
Container(
padding: EdgeInsets.only(right: 120),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
readBlogList.title!,
style: TextStyle(
fontSize: 12,
//fontWeight: FontWeight.bold
),
),
Text(
readBlogList.subTitle!,
style: TextStyle(
fontSize: 12,
//fontWeight: FontWeight.bold
),
),
],
),
),
// SizedBox(width: 130,),
Container(
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xfffee8db),
),
child: Icon(
Icons.done,
color: Color(0xffdd8e8d),
size: 16,
),
)
],
),
),
));
}

}

When we run the application, we ought to get the screen’s output like the underneath screen video.


Conclusion:

In this article, I have explained the setup for the Desktop applications in a flutter.

I hope this blog will provide you with sufficient information on Trying up the Explore, and explain in brief your flutter projects.

❤ ❤ 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.


GitHub Link:

find the source code of the Flutter E-learning Demo app

GitHub – flutter-devs/flutter_app_for_desktop: how to set up for run the application on desktop
Permalink Failed to load the latest commit information. A new Flutter project. This project is a starting point for a…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 Facebook, GitHub, Twitter, 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.


Explore Encrypt & Decrypt Data in Flutter

0

Flutter is a portable UI toolkit. In other words, it’s a comprehensive app Software Development toolkit (SDK) that comes complete with widgets and tools. Flutter is a free and open-source tool to develop mobile, desktop, web applications. Flutter is a cross-platform development tool. This means that with the same code, we can create both IOs and Android apps. This is the best way to save time and resources in our entire process. In this, hot reload is gaining traction among mobile developers. Allows us to quickly see the changes implemented in the code with hot reload.

In this article, we will explore the Flutter Encrypt & Decrypt data files using the crypto package. With the help of this package, users can encrypt and decrypt data in a flutter. So let’s get started.


Table Of Contents::

Encryption & Decryption

Type of Encrypt data

Code Implement

Code File

Conclusion


Introduction:

Encryption is the process of converting the data into an encoded(cipher) data form. if any unauthorized person or entity gains access to it, they will not be able to read it. It is necessary to secure the files to every mobile application or Website passing data on the network before sending them to prevent unauthorized access to their data to the recipient. It helps to protect private and sensitive information and can enhance the security of communication between client apps and servers.

Decryption is the process of converting encoded data from back to a normal(plain) data form. In this post, we are showing how to encrypt input data and then decrypt it back to its normal form.

Demo module::


Type Of Encrypt data:

We will see 3 different types of algorithms to encrypt and decrypt data in a flutter.

1- AES Algorithm :

(Advanced Encryption Standard) has become the encryption algorithm of choice for governments, financial institutions, and security-conscious enterprises around the world. The U.S. National Security Agency (NSC) uses it to protect the country’s “top secret” information.

2- Fernet Algorithm:

Fernet is an asymmetric encryption method that makes sure that the message encrypted cannot be manipulated/read without the key. It uses URL-safe encoding for the keys. Fernet also uses 128-bit AES in CBC mode and PKCS7 padding, with HMAC using SHA256 for authentication. The IV is created from os. random(). All of this is the kind of thing that good software needs.

3- Salsa Algorithm:

Salsa20 is a cipher that was submitted to the eSTREAM project, running from 2004 to 2008, which was supposed to promote the development of stream ciphers. It is considered to be a well-designed and efficient algorithm. There aren’t any known and effective attacks on the family of Salsa20 ciphers.

Code Implementation:

Let’s start with code implementation. To implement the following project you need to integrate the crypto package into your Flutter app.

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

  • > encrypt: ^5.0.1

Now in your Dart code, you can use the following import this package.

import 'package:crypto/crypto.dart';

step 2: I have created a dart file to define AES, Fernet, and Salsa algorithms.

This file has 2 methods for encrypting and decrypt data using the AES algorithm.

class EncryptData{
//for AES Algorithms

static Encrypted? encrypted;
static var decrypted;

static encryptAES(plainText){
final key = Key.fromUtf8('my 32 length key................');
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
encrypted = encrypter.encrypt(plainText, iv: iv);
print(encrypted!.base64);
}

static decryptAES(plainText){
final key = Key.fromUtf8('my 32 length key................');
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
decrypted = encrypter.decrypt(encrypted!, iv: iv);
print(decrypted);
}
}

This file has 2 methods for encrypting and decrypt data using the Salsa algorithm.//for Fernet Algorithms

static Encrypted? fernetEncrypted;
static var fernetDecrypted; static encryptFernet(plainText){
final key = Key.fromUtf8('my32lengthsupersecretnooneknows1');
final iv = IV.fromLength(16);
final b64key = Key.fromUtf8(base64Url.encode(key.bytes));
final fernet = Fernet(b64key);
final encrypter = Encrypter(fernet);
fernetEncrypted = encrypter.encrypt(plainText);
print(fernetEncrypted!.base64); // random cipher text
print(fernet.extractTimestamp(fernetEncrypted!.bytes));
}

static decryptFernet(plainText){
final key = Key.fromUtf8('my32lengthsupersecretnooneknows1');
final iv = IV.fromLength(16);
final b64key = Key.fromUtf8(base64Url.encode(key.bytes));
final fernet = Fernet(b64key);
final encrypter = Encrypter(fernet);
fernetDecrypted = encrypter.decrypt(fernetEncrypted!);
print(fernetDecrypted);
}

Step 3: Now finally call this above method in the home screen dart file.

In this file, I designed a card with 1 Text Field and 2 buttons, and 2 text views to show encrypting and decrypting results. Here are the screenshots and code snippets.

Code File:

import 'package:encrypt_data_demo/encrypt_data.dart';
import 'package:flutter/material.dart';

class HomeView extends StatefulWidget {

@override
_HomeViewState createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {
TextEditingController? _controller=TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
title: Text("Encrypt and Decrypt Data"),
),
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(top:10,bottom: 10),
child: _buildBody(),
),
),
);
}

Widget _buildBody() {
return Container(
height: 280,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.only(left: 10,right: 10),
child: Card(
elevation: 2,
child: Container(
padding: EdgeInsets.only(left: 15,right: 15,top:
15,bottom: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: TextField(
controller: _controller,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter Text',
),
),
),
SizedBox(height: 30),
Text("EncryptText : ${EncryptData.aesEncrypted!=null?EncryptData.aesEncrypted?.base64:''}",
maxLines: 2,
style:TextStyle(
color: Colors.black,
fontSize: 16
),
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 10,),
Expanded(
child: Text("DecryptText : ${EncryptData.aesDecrypted!=null?EncryptData.aesDecrypted:''}",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style:TextStyle(
color: Colors.black,
fontSize: 16
)
),
),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blue, // background
onPrimary: Colors.white,
),
onPressed: () {
setState(() {
EncryptData.encryptAES(_controller!.text);
});
},
child: Text('Encryption'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blue, // background
onPrimary: Colors.white,
),
onPressed: () {
setState(() {
EncryptData.decryptAES(_controller!.text);
});
},
child: Text('Decryption'),
)
],
)
],
),
),
),
);
}
}

Conclusion:

In this article, I have explained the basic overview of the Encrypt data in a flutter, you can modify this code according to your choice. This was a small introduction to Encrypt & Decrypt data On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information on Trying up the Explore, Encrypt & Decrypt data in your flutter projects.

❤ ❤ 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 Facebook, GitHub, Twitter, 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.

Improve code style using lint rules in Flutter

0

In this blog, we shall learn what is linting, how we can implement it in the flutter repository, how it helps to make our dart code effective. There are some packages that are available for us to implement linting into our flutter app that checks for programmatic and stylistic errors such as lint, analyzer, linter. All these packages help to keep the health of the code good and up to the dart standards.


Table Of Contents ::

Important links

Who linting helps?

Writing new linting rules

Enable and disable linting rules

What happens when I added all the rules to my existing repo

analysis_options.yaml

Conclusion



Important links:

Linter for Dart
This list is auto-generated from our sources. Rules are organized into familiar rule groups. In addition, rules can be…dart-lang.github.io

linter | Dart Package
The Dart Linter package defines lint rules that identify and report on “lints” found in Dart code. Linting is performed in…pub.dev

analyzer | Dart Package
This package provides a library that performs static analysis of Dart code. It is useful for tool integration and…pub.dev

How linting helps?:

The purpose of linting is to get real-time suggestions about identifying the hidden error that may improve the code quality or to identify bugs that may cause issues while running the app. For example, if you use Text(“demo”) in any widget then the analyzer will show a warning Prefer const with constant constructors , it means you should keep this widget as const Text("demo") , which I think is really a good suggestion, and most of the time we forget to initialize it using const keywords so I found that using linting is really good practice.

Writing new linting rules:

Now let us see how we can change our settings so that we get an error message every time we use the wrong dart code format. To do this we need to edit analysis_options.yaml the file.

  1. Create analysis_options.yaml a file at the project level.
  2. To show the error message we need to change the analyzer settings, in analyzer we will change the error, warning, ignore, info preferences of individual rules, for example missing_required_param: error , it will always show an error message every time you miss the required parameter.
  3. Also, we will add the linter that will handle all the errors causing missing arguments or might improve the code quality. eg. avoid_empty_else this linter will show an error message whenever we will declare an empty else statement.

Enable and disable linting rules:

We can easily enable and disable linting rules:

linter:

rules:
always_declare_return_types: false
annotate_overrides: true

To analyze the code we need to run dart analyzer . in the terminal.

What happens when I added all the rules to my existing repo?:

I got the following 58 issues, that might decrease my app performance or might cause any issue without an error message so it’s really important to know all the possible errors and solve them first.

All these issues were not visible before the linting and analyzer were added, after resolving all the issues the code quality is really improved and app performance is also improved.

AFTER RESOLVING ALL THE ERROR

analysis_options.yaml:

This file contains all the linter and analyzer. I have added all the linter that might help you. Under the analyzer errors-tag, we can change the preferences of the linters whether we want to show errors or warnings related to that particular linter.

https://gist.github.com/anmolgupta-aeologic/ccfdcaa5e214c070ab938feeb86e49b9#file-analysis_options-yaml

Conclusion:

In the article, I have explained the basic structure of Lint Rules in a flutter; you can modify this code according to your choice. This was a small introduction to the Lint Rules On User Interaction from my side, and it’s working using Flutter.

I hope this blog will provide you with sufficient information on Trying up the Lint Rules in your flutter projects. In this blog, we have examined the Lint Rules. I hope this blog will help you in the comprehension of the Lint Rules in a better way. So please try it.

🌸🌼🌸 Thank you for reading 🌸🌼🌸

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 Facebook, GitHub, Twitter, 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.


Positioned Transition Widget In Flutter

0

Whenever building an app animation plays a vital role in designing the experience of the user. People tend to like an app that has a smooth flow and a slick design. The Flutter Package provides a variety of methods to create and use animation in our app. We will be discussing the inbuilt Flutter widgets to handle animation.

In this article, we will explore the Positioned Transition Widget. We will see how to implement a demo program to create a sample app that shows an animation in your flutter applications.

Animated version of Positioned which takes a specific Animation<RelativeRect> to transition the child’s position from a start position to an end position over the lifetime of the animation. Only works if it’s the child of a Stack. These are the simplest widget provided by flutter. These widgets can be implemented without much work from the developer. These are very basic animation techniques, so they don’t have many options available to be changed. They have the properties to control the repetition and movement of the widget. These widgets require a Controller for the granular control they provide.


Table Of Contents::

Introduction

Properties

Use of Positioned Transition

Conclusion

GitHub Link


Introduction:

Hello everyone, This is my first ever article on Flutter. Positioned Transition is a very powerful widget if we look deep into it. It provides us with an interface using the Positioned Transition so that we can do various types of animations. We change the position of a widget with animation by using Positioned Transition widget. You’ll see that using widgets and animating them can make your app more visually appealing.

Positioned Transition widget allows for a child to move from one position to another in an animation.

The Default Constructor of it will look like below:

PositionedTransition({
Key key,
@required Animation<RelativeRect> rect,
@required Widget child,
});

Properties:

  • > child: The widget below this widget is in the tree. This widget can only have one child. To layout multiple children, let this widget’s child be a widget such as Row, Column, or Stack, which have a children property, and then provide the children to that widget.

Implementation:

final Widget child;
  • > key: It’s controls how one widget replaces another widget in the tree. Using a GlobalKey as the widget’s key allows the element to be moved around the tree (changing parent) without losing state. When a new widget is found (its key and type do not match a previous widget in the same location), but there was a widget with that same global key elsewhere in the tree in the previous frame, then that widget’s element is moved to the new location. Generally, a widget that is the only child of another widget does not need an explicit key.

Implementation:

final Key key;
  • > Animation<RelativeRect> rect: An immutable 2D, axis-aligned, floating-point rectangle whose coordinates are given relative to another rectangle’s edges, known as the container. This parameter is used to define the animation that controls the child’s size and position. It determines the width or height of the rectangle, converts it to a Rect using toRect() (passing the container’s own Rect), and then examines that object. The fields left, right, bottom, and top must not be null.

Implementation:

RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0)

Implementation:

const RelativeRect.fromLTRB(
this.left,
this.top,
this.right,
this.bottom)
: assert(
left != null && top != null && right != null && bottom != null);

RelativeRect.fromRect(Rect rect, Rect container) Creates a RelativeRect from two Rects. The second Rect provides the container, the first provides the rectangle, in the same coordinate space, that is to be converted to a RelativeRect. The output will be in the container’s coordinate space.

Implementation:

factory RelativeRect.fromRect(Rect rect, Rect container) {
return RelativeRect.fromLTRB(
rect.left – container.left,
rect.top – container.top,
container.right – rect.right,
container.bottom – rect.bottom
); }

RelativeRect.fromSize(Rect rect, Size container). Creates a RelativeRect from a Rect and a Size. The Rect (first argument) and the RelativeRect (the output) are in the coordinate space of the rectangle described by the Size, with 0,0 being at the top left.

Implementation:

factory RelativeRect.fromSize(Rect rect, Size container) {
return RelativeRect.fromLTRB(
rect.left,
rect.top,
container.width - rect.right,
container.height - rect.bottom);
}

  • > listenable: The listeners are typically used to notify clients that the object has been updated.

Use of Positioned Transition:

For the “Positioned Transition” first we need to create an AnimatedController() in which we pass the duration for the animation. and create a dispose of () for dispose of the controller. After that we create a method that returns the Container() and returns the GestureDetector() as a child of the container, In the onTap() we pass a condition that if the controller has completed so it revers the image otherwise foreword the image. and pass image as a child of GestureDetector().

positioned_transition_home.dart

In BuildContext() we pass the variable smallSize and largeSize and also pass the screenSize. In the body of the class, we pass stack because in this we have to take stack as a child, and pass PositionedTransition() as a child and in the properties of positionedTransition we use rect, In this, we use RelativeRectTween() for set the begin and end. And use animate(), we pass controller as a parent of CurvedAnimation() and pass curve. After that, we return the method which returns the container.

When we run the application, we ought to get the screen’s output like the underneath screen capture.


Conclusion:

In this article, we have been through What is Positioned Transition Widget in Flutter along with how to implement it in a Flutter. You can use the package according to your requirement.

❤ ❤ 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.

GitHub Link:

find the source code of the Positioned Transition Widget:

GitHub – flutter-devs/PositionedTransition
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 Facebook, GitHub, Twitter, 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.


Motion Toast In Flutter

0

In this article, we will explore the Motion Toast In Flutter. We will see how to implement a demo program to create a motion toast and also shows a display animation in your flutter applications.


Table Of Contents:

What is Motion Toast?

Installation

Flutter motion toast attributes

Flutter Motion Toast / Styled Toast Built-In Types

Conclusion

GitHub Link


What is Motion Toast?:

Motion toast is an open-source flutter package that lets you display messages in toast in a user-friendly way, with multiple built-in themes.

Motion toast also has built-in display animations and you can define its position (Bottom, Center, Top).

Installation:

To create and show a motion toast message in flutter follow the steps below:

  • > Create a flutter project
  • > Add motion_toast dependency to the project
  • > Import the motion toast package:-
import 'package: motion_toast/motion_toast.dart';
  • > Implement code for creating and showing motion toast in a flutter.

Run this command:

OR

To get motion_toast working on your project all you need to do is to add this line to your pubspec.yaml file under dependencies

Flutter Motion Toast Attributes:

1:-description the String content that will be used in the motion toast itself will be displayed to users, this parameter is required for all constructors.

MotionToast(
icon: Icons.alarm,
primaryColor: Colors.red,
description: 'this is description',
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

2:- title:- the title is String toast, by default, it’s an empty string for all the constructors.

MotionToast(
icon: Icons.alarm,
primaryColor: Colors.red,
description: 'this is description',
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

3:- descriptionStyle is the text style that will be applied to the description text.

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
descriptionStyle: TextStyle(
fontSize: 14,
color: Colors.deepOrange
),
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

4:- titleStyl is the text style that will be applied on the title text.

MotionToast(
primaryColor: Colors.blue,
description: "This is description",
icon: Icons.message,
title: "Message",
titleStyle: TextStyle(
fontSize: 16,
fontWeight:FontWeight.bold,
color: Colors.deepOrange
),
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

5:-icon is the IconData that will render in the motion toast, this parameter is required when creating a custom toast otherwise you don’t have to pass it.

MotionToast(
primaryColor: Colors.yellow,
description: "This is description",
icon: Icons.video_label,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

6:-primaryColor The motion toast background color (applied on the background), this parameter is required when creating a custom toast otherwise you don’t have to pass it.

MotionToast(
icon: Icons.alarm,
primaryColor: Colors.red,
description:
'this is description',
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

7:-widththe width of the toast is not required & its default value is 350.

MotionToast(
primaryColor: Colors.blue,
description: "This is description",
icon: Icons.message,
width: 300,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

8:-height the height of the toast & its default value is 80.

MotionToast(
primaryColor: Colors.blue,
description: "This is description",
icon: Icons.message,
width: 300,
height: 130,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

9:-iconSizethis is required a double value & its default value is 40.

MotionToast(
primaryColor: Colors.yellow,
description: "This is description",
icon: Icons.message,
iconType: ICON_TYPE.CUPERTINO,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

10:-iconType the style type of the icon (Cupertino or Material Design).

MotionToast(
primaryColor: Colors.red,
description: "This is description",
icon: Icons.message,
iconType: ICON_TYPE.cupertino,
).show(context);

11:-enableAnimation define whether the toast will be animated or not, by default it’s true.MotionToast(
primaryColor: Colors.yellow,
description: “This is description”,
icon: Icons.message,
enableAnimation: false,
).show(context);

12:-layoutOrientation define how the toast layout will be rendered LTR or RTL.

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
layoutOrientation: ORIENTATION.rtl,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

13:-animationType the type of animation applied to the toast (From the bottom, from left, from right, from top) by default its value is from the bottom.

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
animationType: ANIMATION.fromLeft,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen video.

14:-animationDurationthe duration of the animation by default its value is Duration(milliseconds: 1500) .

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
enableAnimation: false,
animationDuration: Duration(seconds: 3),
).show(context);

15:-toastDurationthe duration the how much the toast will be shown, by default the toast takes 3 seconds.

MotionToast(
primaryColor: Colors.blue,
description: "This is description",
icon: Icons.message,
toastDuration: Duration(seconds: 3),
).show(context);

16:-animationCurvethe animation rendering curve, by default its value is Curves.ease.

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
animationCurve: Curves.bounceIn,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen video.

17:-positionthe position where the toast will be displayed (TOP, BOTTOM, CENTER).

MotionToast(
primaryColor: Colors.green,
description: "This is description",
icon: Icons.message,
position: MOTION_TOAST_POSITION.TOP,
animationType: ANIMATION.FROM_TOP,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

18:-borderRadiusthe radius of the borders of the toast.

MotionToast(
primaryColor: Colors.yellow,
description: "This is description",
icon: Icons.message,
borderRadius: 20,
).show(context);

19:-onClosefunction invoked once the toast is closed.

MotionToast(
primaryColor: Colors.purple,
description: "This is description",
icon: Icons.message,
onClose: (){
print("close");
},
).show(context);

20:-dismissabledefine whether the toast can be dismissed or not (applied only on bottom motion toast).

MotionToast(
primaryColor: Colors.purple,
description: "This is description",
icon: Icons.message,
dismissable: true,
).show(context);

21:-secondaryColorSecondary color applied on the sidebar and the icon (available when using the default constructor).MotionToast(
primaryColor: Colors.purple,
description: “This is description”,
icon: Icons.message,
secondaryColor: Colors.grey,
).show(context);

22:-backgroundTypedefine the background style transparent, solid, or lighter.

MotionToast(
primaryColor: Colors.purple,
description: "This is description",
icon: Icons.message,
backgroundType: BACKGROUND_TYPE.lighter,
).show(context);

Flutter Motion Toast / Styled Toast Built-In Types:

1:-Success

MotionToast.success(
title: "Success Motion Toast",
description: "Example of success motion toast",
width: 300,
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

2:-Error

MotionToast.error(
title: "Error",
description: "Example of error toast"
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

3:-Warning

MotionToast.warning(
title: "Warning Motion Toast",
description: "This is a Warning toast "
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

4:-Delete

MotionToast.delete(
title: "Deleted",
description: "The item is deleted"
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

5:-Info

MotionToast.info(
title: "Info Motion Toast",
description: "Example of Info Toast"
).show(context);

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Final Output:

When we run the application, we ought to get the screen’s output like the underneath screen capture.

Conclusion:

In this article, we discussed how this package can be used, what are all the parameters that you can use to customize the display of it, and also it provides multiple features to customize the toast.

❤ ❤ 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.

GitHub Link:

find the source code of the Motion Toast:

GitHub – flutter-devs/flutter_motion_toast
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…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 Facebook, GitHub, Twitter, 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.


GestureDetector In Flutter

0

When it comes to creating applications, you have to handle user reactions such as touch and drags. This makes your application interactional beneficially handle gestures, you need to listen to the gestures and greet them. Flutter offers a change of widgets that help add interactivity to your apps.

In this article, we will explore the GestureDetector In Flutter. We will see how to implement a demo program to create a GestureDetector and also shows properties in your flutter applications.


Table Of Contents::

Introduction

Properties

Implementation

Conclusion

GitHub Link


Introduction:

There are many widgets in a flutter, like Container, Column, Text, etc. They don’t have a basic way of detecting gestures. Such widgets are covered in the “GestureDetector” widget which is simply used for detecting gestures and does not give any visual response like a wave effect.

It’s a widget that detects gestures. Attempts to acknowledge gestures that correspond to its non-null callbacks. If this widget has a child, it stays with that child for its sizing behavior. If it does not have a child, it fattens to fit the parent instead. By default a Gesture Detector with an unseeable child ignores touches; this behavior can be supervised with behavior. Gesture Detector also listens for accessibility events and maps them to the callbacks. To ignore availability events.

GestureDetector({
Key key,
Widget? child,
void Function(TapDownDetails)? onTapDown,
void Function(TapUpDetails)? onTapUp,
void Function()? onTap,
void Function()? onTapCancel,
void Function()? onSecondaryTap,
});

Properties:

There are some properties of GestureDetector are:

  • > child: This widget can only have one child. To layout multiple children, let this widget’s child be a widget such as Row, Column, or Stack, which have a children property, and then provide the children to that widget.

Implementation:

final Widget? child;
  • onTap(): Touching the surface of the device with a fingertip for a short period and then releasing the fingertip.

Implementation:

final GestureTapCallback? onTap;
  • onTapDown(): Triggered when the user makes contact with the screen, might be a tap.

Implementation:

final GestureTapDownCallback? onTapDown;
  • onDoubleTap(): The user tapped the screen at the same location twice in quick succession.

Implementation:

final GestureTapCallback? onDoubleTap;
  • onHorizontalDragEnd(): A pointer that was previously in contact with the screen with a primary button and moving horizontally is no longer in contact with the screen and was moving at a specific velocity when it stop final GestureDragEndCallback? onHorizontalDragEnd;ped contacting the screen.

Implementation:

final GestureDragEndCallback? onHorizontalDragEnd;
  • onDoubleTapDown(): The pointer that previously triggered onDoubleTapDown will not end up causing a double-tap.

Implementation:

final GestureTapCancelCallback? onDoubleTapCancel;
  • onLongPress(): Triggered when a pointer has remained in contact with the screen at the same location for a long period.

Implementation:

final GestureLongPressCallback? onLongPress;

Implementation:

In the Gesture Detector demo, first, we take a Stateful class and create color and text variable in which we pass the initial color, the value of color is Teal and the value of the text is “Hello! it’s Teal Color”.

In BuildContext() we return Scaffold() and use the property of AppBar() and pass the title of the application. In the body of Scaffold(), we pass Center() and after that, we pass GestureDetector() as a child of it. We create a Container() and pass the color and text which is already passed the code. And use the properties of GestureDetector(), We use onTap(): onTap() is used when the user makes contact with the screen, which might be a tap.

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepPurpleAccent,
centerTitle: true,
title: Text('Gesture Detector Demo'),
),
body: Center(
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(20)
),
width: 250,
height: 200,
child: Center(
child: text,
)),
),
),
);
}

In the onTap() we pass the setState() and in the setState() we pass the different colors which are Amber colors and pass the new Text “Hello! it’s Amber Color”. When we click on that container, The color, and the text will be changed.

onTap: (){
setState(() {
color = Colors.amber;
text = Text("Hello! it's Amber Color",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),);
});
},

After that, we use onDoubleTap(): onDoubleTap() is used when the user tapped the screen at the same location twice in quick succession. In this, we pass the setState() and in this, we pass the different color which is Blue color and pass the new Text “Hello! it’s Blue Color”. When we double click on that container, The color, and the text will be changed.

onDoubleTap: (){
setState(() {
color = Colors.blueAccent;
text = Text("Hello! it's Blue Color",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),);
});
},

And at last, we create onLongPress(): onLongPress() is used when a pointer has remained in contact with the screen at the same location for a long period. In this, we pass the setState() and in this, we pass the different color which is Orange color, and pass the new Text “Hello! it’s Orange Color”. When we press the container for a long time, The color and the text will be changed.

onLongPress: (){
setState(() {
color = Colors.deepOrangeAccent;
text = Text("Hello! it's Orange Color",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold
),);
});
},

When we run the application, we ought to get the screen’s output like the underneath screen video.


Conclusion:

In this article, we have been through What is GestureDetector in Flutter along with how to implement it in a Flutter. By using we can perform many orations of tap or we can say we can perform different type onClick. You can use this according to your requirement.

❤ ❤ 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.


GitHub Link:

find the source code of the Gesture Detector:

GitHub – flutter-devs/flutter_gesture_detector
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…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 Facebook, GitHub, Twitter, 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.