Google search engine
Home Blog Page 26

How to use GetX Dialogs in Flutter 2026

0

Dialogs are fundamental parts of mobile Apps. They help to pass cautions and significant messages as well as on to do specific activities. At the point when flutter developers make a dialog in Flutter, it utilizes context and builder to make a Dialog. However, this training isn’t appropriate for a developer to foster Dialogs utilizing contexts and builders.

In this article, we will explore the Dialog Using GetX in Flutter. We will also implement a demo program and learn how to create Dialog using the get package in your flutter applications.

get | Flutter Package
GetX is an extra-light and powerful solution for Flutter. It combines high-performance state management, intelligence…pub.dev

Table Of Contents::

Introduction

Constructor

Properties

Implementation

Code Implement

Code File

Conclusion



Introduction:

At the point when we need to show anything like the form then we can make this Dialog involving the GetX library in Flutter. We can make Dialog utilizing GetX with basic code and extremely simple to make a dialog. It doesn’t utilize context and builder to make Dialog.

GetX is additional light and strong solution for Flutter. It joins elite performance state management, intelligent dependency injection, and route management rapidly and essentially.

Demo Module ::

This demo video shows how to create a dialog in a flutter and shows how dialog will work using the get package in your flutter applications, and also using different properties. It will be shown on your device.

Constructor:

To utilize Get.defaultDialog(), you need to call the constructor underneath:

Future<T?> defaultDialog<T>({
String title = "Alert",
EdgeInsetsGeometry? titlePadding,
TextStyle? titleStyle,
Widget? content,
EdgeInsetsGeometry? contentPadding,
VoidCallback? onConfirm,
VoidCallback? onCancel,
VoidCallback? onCustom,
Color? cancelTextColor,
Color? confirmTextColor,
String? textConfirm,
String? textCancel,
String? textCustom,
Widget? confirm,
Widget? cancel,
Widget? custom,
Color? backgroundColor,
bool barrierDismissible = true,
Color? buttonColor,
String middleText = "Dialog made in 3 lines of code",
TextStyle? middleTextStyle,
double radius = 20.0,
List<Widget>? actions,
WillPopCallback? onWillPop,
GlobalKey<NavigatorState>? navigatorKey,
})

Properties:

There are some properties of Get.defaultDialog() are:

  • > title: In this property is used to the title of the Dialog. By default, the title is “Alert”.
  • > titleStyle: In this property is used to the style given to the title text using TextStyle.
  • > content: In this property is used to the content given to the Dialog and should use Widget to give content.
  • > middleText: In this property is used in the middle text given to the Dialog. If we utilize content also then content widget data will be sown.
  • > barrierDismissible: In this property is used if we want to close the Dialog by clicking outside the dialog then its value should be true else false. By default, its value is true.
  • > middleTextStyle: In this property is used to the style given to the middle text using TextStyle.
  • > radius: In this property is utilized to the radius of the Dialog provided. By default, its value is 20.
  • > backgroundColor: In this property is used as the background color of the Dialog.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:
flutter:
sdk: flutter
get: ^4.6.1

Step 2: Import

import 'package:get/get.dart';

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

How to implement code in dart file :

You need to implement it in your code respectively:

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

We have utilized GetMaterialApp rather than MaterialApp because we are building our application utilizing the GetX library. If we don’t utilize GetMaterialApp then, at that point, its functionalities won’t work.

return GetMaterialApp(
title: 'Dialog Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Splash(),
debugShowCheckedModeBanner: false,
);

We will create a Home class in the main.dart file

In the body, we will add a Center widget. In this widget, we will add a Column widget that was mainAxisAlignment was center. We will add things, first, we will add an image, and second, we will add an ElevatedButton with child and style properties. In the onPressed function, we will add Get.defaultDialog(). We will deeply describe it below.

Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assets/logo.png", scale: 14,),
SizedBox(height: 80,),
ElevatedButton(
child: Text('Show Dialog'),
style: ElevatedButton.styleFrom(
primary: Colors.teal,
onPrimary: Colors.white,
shadowColor: Colors.tealAccent,
textStyle: TextStyle(
fontSize: 18,
),
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
minimumSize: Size(120, 50),
),
onPressed: () {
Get.defaultDialog();

},
),
],
)),

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

Home Screen

Now, we will deeply describe Get.defaultDialog():

Now you saw how easy it is to get a dialog with very few lines using GetX in Flutter. You can also customize it with different options given by GetX. We will add title, middle text, backgroundColor, titleStyle, middleTextStyle and radius.

Get.defaultDialog(
title: "Welcome to Flutter Dev'S",
middleText: "FlutterDevs is a protruding flutter app development company with "
"an extensive in-house team of 30+ seasoned professionals who know "
"exactly what you need to strengthen your business across various dimensions",
backgroundColor: Colors.teal,
titleStyle: TextStyle(color: Colors.white),
middleTextStyle: TextStyle(color: Colors.white),
radius: 30
);

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

Final Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_dialog_getx_demo/splash_screen.dart';
import 'package:get/get.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Dialog Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Splash(),
debugShowCheckedModeBanner: false,
);
}
}

class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Dialog Using GetX In Flutter'),
centerTitle: true,
backgroundColor: Colors.cyan,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assets/logo.png", scale: 14,),
SizedBox(height: 80,),
ElevatedButton(
child: Text('Show Dialog'),
style: ElevatedButton.styleFrom(
primary: Colors.teal,
onPrimary: Colors.white,
shadowColor: Colors.tealAccent,
textStyle: TextStyle(
fontSize: 18,
),
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
minimumSize: Size(120, 50),
),
onPressed: () {
Get.defaultDialog(
title: "Welcome to Flutter Dev'S",
middleText: "FlutterDevs is a protruding flutter app development company with "
"an extensive in-house team of 30+ seasoned professionals who know "
"exactly what you need to strengthen your business across various dimensions",
backgroundColor: Colors.teal,
titleStyle: TextStyle(color: Colors.white),
middleTextStyle: TextStyle(color: Colors.white),
radius: 30
);
},
),
],
)),
);
}
}

Conclusion:

In the article, I have explained the basic structure of the Dialog Using GetX in a flutter; you can modify this code according to your choice. This was a small introduction to Dialog Using GetX 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 Dialog Using GetX in your flutter projects. We will show you what the Introduction is?. Make a demo program for working Dialog Using GetX plugins. In this blog, we have examined the Dialog Using GetX of the flutter app. I hope this blog will help you in the comprehension of the Dialog 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 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: Pagination using GetX in Flutter

Related: Rest API Using GetX

Related: GetX State Management In Flutter


Frequently Asked Questions

How can I create a dialog box in Flutter using the GetX state management library?

You can create a dialog box in Flutter by using Get.dialog() function from the GetX package.

What are the benefits of using GetX for creating dialogs in Flutter instead of other state management solutions?

GetX simplifies the creation and handling of dialogs, making it easier to manage complex UI states.

Can I customize the appearance of dialogs created using GetX in Flutter?

Yes, you can customize the appearance of your dialogs by passing a custom widget to the Get.dialog() function.

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

ExpansionPanelList In Flutter

0

In this article, we will explore the ExpansionPanelList In Flutter. We will implement an expansion panel list demo program and learn how to customize its style with different properties in your flutter applications.

Table Of Contents::

Expansion Panel List

Constructor

Properties

Code Implement

Code File

Conclusion



Expansion Panel List:

It is a material widget in flutter which is like listView. It can just have Expansion panels as children. In certain cases, we may need to show a list where the children can expand/collapse to show/hide some detailed data. To show such a list flutter gives a widget called ExapansionPanelList.

In this list, every child is an ExpansionPanel widget. We can’t utilize different widgets as children for this list. We can deal with the adjustment of state( Expansion or collapse ) of a thing with the assistance of ExpansionCallback property.

Demo Module :

This demo video shows how to create an expansion panel List in a flutter. It shows how the expansion panel List will work in your flutter applications. It shows a list where the children can expand/collapse to show/hide some detailed information. It will be shown on your device.

Constructor:

To utilize ExpansionPanelList, you need to call the constructor underneath:

const ExpansionPanelList({
Key? key,
this.children = const <ExpansionPanel>[],
this.expansionCallback,
this.animationDuration = kThemeAnimationDuration,
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
this.elevation = 2,
})

Properties:

There are some properties of ExpansionPanelList are:

  • > children: This property is used by the children of the expansion panel List. They are laid out similarly to [ListBody].
  • > expansionCallback: This property is used to the callback that gets called whenever one of the expand/collapse buttons is pressed. The arguments passed to the callback are the index of the pressed panel and whether the panel is currently expanded or not.
  • > animationDuration: This property is used while expanding or collapsing we can observe some animation take place for a certain period. We can change that duration by using the animationDuration property of the expansion panel List. We just have to provide Duration in either microseconds, milliseconds, or minutes as value.
  • > expandedHeaderPadding: This property is used to the padding that surrounds the panel header when expanded. By default, 16px of space is added to the header vertically (above and below) during expansion.
  • > dividerColor: This property is used to define the color for the divider when [ExpansionPanel.isExpanded] is false. If `dividerColor` is null, then [DividerThemeData.color] is used. If that is null, then [ThemeData.dividerColor] is used.
  • > elevation: This property is used to define elevation for the [ExpansionPanel] while it’s expanded. This uses [kElevationToShadow] to simulate shadows, it does not use [Material]’s arbitrary elevation featureBy default, the value of elevation is 2.

How to implement code in dart file :

You need to implement it in your code respectively:

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

First, we will generate dummy data. We will create a list <Map<String, dynamic>> and add variable _items equal to generating a list. In this list, we will add number, id, title, description, and isExpanded.

List<Map<String, dynamic>> _items = List.generate(
10,
(index) => {
'id': index,
'title': 'Item $index',
'description':
'This is the description of the item $index. Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'isExpanded': false
});

In the body, we will add ExpansionPanelList() widget. In this widget, we will add elevation was three, expansionCallback was added index and isExpanded in the bracket. We will add setState() method. Inside the method, we will add _items[index][‘isExpanded’] equal not isExpanded.

ExpansionPanelList(
elevation: 3,
expansionCallback: (index, isExpanded) {
setState(() {
_items[index]['isExpanded'] = !isExpanded;
});
},
animationDuration: Duration(milliseconds: 600),
children: _items
.map(
(item) => ExpansionPanel(
canTapOnHeader: true,
backgroundColor:
item['isExpanded'] == true ? Colors.cyan[100] : Colors.white,
headerBuilder: (_, isExpanded) => Container(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(
item['title'],
style: TextStyle(fontSize: 20),
)),
body: Container(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(item['description']),
),
isExpanded: item['isExpanded'],
),
)
.toList(),
),

We will add animationDuration was 600 milliseconds. We will add children as variable _items were mapped to the ExpansionPanel() widget. In this widget, we will add canTapOnHeader was true, backgroundColorheaderBuilder return the Container() widget. In this widget, we will add padding and on its child property, we will add text. In the body, we will add Conatiner and its child property, we will add text. When we run the application, we ought to get the screen’s output like the underneath screen capture.

Final Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_expansion_panel_list/splash_screen.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: Splash());
}
}

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

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

class _HomePageState extends State<HomePage> {
List<Map<String, dynamic>> _items = List.generate(
10,
(index) => {
'id': index,
'title': 'Item $index',
'description':
'This is the description of the item $index. Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
'isExpanded': false
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Flutter Expansion Panel List Demo'),
),
body: SingleChildScrollView(
child: ExpansionPanelList(
elevation: 3,
// Controlling the expansion behavior
expansionCallback: (index, isExpanded) {
setState(() {
_items[index]['isExpanded'] = !isExpanded;
});
},
animationDuration: Duration(milliseconds: 600),
children: _items
.map(
(item) => ExpansionPanel(
canTapOnHeader: true,
backgroundColor:
item['isExpanded'] == true ? Colors.cyan[100] : Colors.white,
headerBuilder: (_, isExpanded) => Container(
padding:
EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(
item['title'],
style: TextStyle(fontSize: 20),
)),
body: Container(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
child: Text(item['description']),
),
isExpanded: item['isExpanded'],
),
)
.toList(),
),
),
);
}
}

Conclusion:

In the article, I have explained the basic structure of the ExpansionPanelList in a flutter; you can modify this code according to your choice. This was a small introduction to ExpansionPanelList 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 ExpansionPanelList in your flutter projects. We will show you what the ExpansionPanelList is?. Show constructor and properties of the ExpansionPanelListr. Make a demo program for working ExpansionPanelList, and it shows a list where the children can expand/collapse to show/hide some detailed information in your flutter application. 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 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

Related: Using SharedPreferences in Flutter

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


Implement ActionListener In Flutter

0

Listeners on the Action class should have their listener callbacks eliminated with Action.removeActionListener when the listener is disposed of. This widget assists with that. It gives a lifetime to the association between the listener and the Action. It additionally helps by taking care of the adding and removing of the listener at the right focuses in the widget lifecycle.

In this article, we will explore the Implement ActionListener In Flutter. We will implement an ActionListener demo program and how to use it in your flutter applications.

ActionListener class – widgets library – Dart API
A helper widget for making sure that listeners on action are removed properly. Listeners on the Action class must…api. flutter.dev

Table Of Contents::

Introduction

Constructor

Properties

Implementation

Code Implement

Code File

Conclusion



Introduction:

ActionListener is the helper widget. You can utilize it to remove listeners from the activity. If you pay attention to an Action widget in a widget hierarchy, you should utilize this widget. If you are utilizing an Action outside of a widget context, you should call removeListener yourself.

Demo Module :

This demo video shows how to implement an ActionListener widget in a flutter. It shows how the ActionListener will work in your flutter applications. It shows where the user presses the action listener button, then a message will be shown on the bottom of a screen. It will be shown on your device.

Constructor:

To utilize ActionListener, you need to call the constructor underneath:

const ActionListener({
Key? key,
required this.listener,
required this.action,
required this.child,
})

In the above Constructor, all fields marked with @required must not be empty.

Properties:

There are some properties of ActionListener are:

  • > action: This property is used to the action that the callback will be registered with.
  • > child: This property is used to the 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.
  • > hashCode: This property is used to the hash code for this object.
  • > key: This property is used to control how one widget replaces another widget in the tree.
  • > listener: This property is used to the ActionListenerCallback callback to register with the action.
  • > runtimeType: This property is used to the representation of the runtime type of the object.

How to implement code in dart file :

You need to implement it in your code respectively:

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

First, we will create an ActionListenerDemo class on this dart file. We will create a bool variable _on is equal to false and the final MyAction class was _myAction variable.

bool _on = false;
late final MyAction _myAction;

Lets describe MyAction class are:

MyAction class was extended Action<MyIntent> and we will add three override methods. First, we will add addActionListener in the bracket we will add (ActionListenerCallback listener). When we enable that button then ‘Action Listener was added’ print on the terminal. Second, we will add removeActionListener in the bracket we will add (ActionListenerCallback listener). When we disable that button then ‘Action Listener was removed’ prints on the terminal. Third, we will add invoke in the bracket we will add (covariant MyIntent intent). They will work notifyActionListeners().

class MyAction extends Action<MyIntent> {
@override
void addActionListener(ActionListenerCallback listener) {
super.addActionListener(listener);
print('Action Listener was add');
}

@override
void removeActionListener(ActionListenerCallback listener) {
super.removeActionListener(listener);
print('Action Listener was remove');
}

@override
void invoke(covariant MyIntent intent) {
notifyActionListeners();
}
}

We will create an initState() method. In this method, we will add _myAction variable is equal to the MyAction() class.

@override
void initState() {
super.initState();
_myAction = MyAction();
}

We will create a _toggleState() method. In this method, we will add setState() function. This function will add _on bool variables equal to the not !_on.

void _toggleState() {
setState(() {
_on = !_on;
});
}

In the body, we will add the Padding widget. In this widget, we will add a Container with width and height. It’s child property, we will add OutlinedButton() widget. Inside the widget, we will add style, onPressed method, and its child property we will add text “_on? ‘Disable’: ‘Enable’ “. When _on bool variable is true then Enable button will be shown else Disable button will be shown.

Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 100,
height: 38,
child: OutlinedButton(
style:OutlinedButton.styleFrom(primary: Colors.cyan, ) ,
onPressed: _toggleState,
child: Text(_on ? 'Disable' : 'Enable'),
),
),
),

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

Output

We will add ActionListener() widget. We will add if (action.intentType == MyIntent) then show a showSnackBar message and text ‘Action Listener Call’/ on listener. We will add an _myAction variable on action. We will add ElevatedButton() on its child property.

if (_on)
Padding(
padding: const EdgeInsets.all(8.0),
child: ActionListener(
listener: (Action<Intent> action) {
if (action.intentType == MyIntent) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
backgroundColor: Colors.blueGrey,
content: Text('Action Listener Call'),
));
}
},
action: _myAction,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.cyan),
),
onPressed: () => const ActionDispatcher()
.invokeAction(_myAction, const MyIntent()),
child: const Text('Call Action Listener'),
),
),
),
if (!_on) Container(),

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

Final Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_action_listner_demo/splash_screen.dart';

void main() => runApp(const MyApp());

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


@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Splash(),
);
}
}

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

@override
State<ActionListenerDemo> createState() => _ActionListenerDemoState();
}

class _ActionListenerDemoState extends State<ActionListenerDemo> {
bool _on = false;
late final MyAction _myAction;

@override
void initState() {
super.initState();
_myAction = MyAction();
}

void _toggleState() {
setState(() {
_on = !_on;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: Colors.cyan,
title: Text("Flutter ActionListener Demo")
),
body: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 100,
height: 38,
child: OutlinedButton(
style:OutlinedButton.styleFrom(primary: Colors.cyan, ) ,
onPressed: _toggleState,
child: Text(_on ? 'Disable' : 'Enable'),
),
),
),
if (_on)
Padding(
padding: const EdgeInsets.all(8.0),
child: ActionListener(
listener: (Action<Intent> action) {
if (action.intentType == MyIntent) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
backgroundColor: Colors.blueGrey,
content: Text('Action Listener Call'),
));
}
},
action: _myAction,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.cyan),
),
onPressed: () => const ActionDispatcher()
.invokeAction(_myAction, const MyIntent()),
child: const Text('Call Action Listener'),
),
),
),
if (!_on) Container(),
],
),
),
);
}
}

class MyAction extends Action<MyIntent> {
@override
void addActionListener(ActionListenerCallback listener) {
super.addActionListener(listener);
print('Action Listener was add');
}

@override
void removeActionListener(ActionListenerCallback listener) {
super.removeActionListener(listener);
print('Action Listener was remove');
}

@override
void invoke(covariant MyIntent intent) {
notifyActionListeners();
}
}

class MyIntent extends Intent {
const MyIntent();
}

Conclusion:

In the article, I have explained the basic implementation of the ActionListener in a flutter; you can modify this code according to your choice. This was a small introduction to ActionListener 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 ActionListener in your flutter projects. We will show you what the Introduction is?. Show constructor and properties of the ActionListener. Make a demo program for working ActionListener, and it shows where the user presses the action listener button, then a message will be shown on the bottom of a screen in your flutter application. 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 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

Related: Using SharedPreferences in Flutter

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


Explore Polygon Clipper In Flutter

0

It can be utilized by Clipper to clip the widget into any ideal shape. In Flutter, it very well may be done effectively because of built-in clippers like ClipOval, ClipRect, ClipRRect, and ClipPath. To accomplish this polygon shape you want to characterize what is the way which you want to clip to make your UI marvelous.

In this article, we will Explore Polygon Clipper In Flutter. We will implement a polygon clipper demo program and create a different polygon shape using the polygon_clipper package in your flutter applications.

polygon_clipper | Flutter Package
A Flutter plugin to create views using regular polygon shapes (e.g. Pentagons and Hexagons).pub.dev

Table Of Contents ::

Introduction

Constructor

Attributes

Implementation

Code Implement

Code File

Conclusion



Introduction:

Polygon clippers can be utilized to make distinctively shaped cards. After completing this article you will realize how to clip a widget into polygons with sides more noteworthy than three. You will figure out how to make a pentagonal shape, hexagonal shape, octagonal shape, etc.

Demo Module :

This demo video shows how to create a polygon clipper in a flutter. It shows how the polygon clipper will work using the polygon_clipper package in your flutter applications. It shows a pentagonal, hexagonal, octagonal shape and inside a network image using Polygon clippers. It will be shown on your device.

Constructor:

To utilize ClipPolygon, you need to call the constructor underneath:

ClipPolygon(
{@required this.child,
@required this.sides,
this.rotate: 0.0,
this.borderRadius: 0.0,
this.boxShadows: const []
}
);

In the above Constructor, all fields marked with @required must not be empty.

Attributes:

There are some attributes of ClipPolygon are:

  • > sides— This attribute is used to the number of sides of the polygon. In the above example, we have given the value of sides as 5 means pentagonal shape. To make a hexagonal shape just make the value of sides 6 and also make a different shape according to sides.
  • > borderRadius — This attribute is used to smoothen out the pointy edges. You can change the value to improve the aesthetics or accordance with the general theme you follow for your app.
  • > rotate — This attribute is used so you can specify the angle of rotation in degrees. For example, we have rotated the polygon 90 and 70 degrees in the above code
  • > boxShadows This attribute is used you can also customize the box-shadow to change the perceived elevation of the card.
  • > child — This attribute is used to the 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:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:
flutter:
sdk: flutter
polygon_clipper: ^1.0.2

Step 2: Import

import 'package:polygon_clipper/polygon_clipper.dart';

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

How to implement code in dart file :

You need to implement it in your code respectively:

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

We will create three shapes of polygon clippers are pentagonal, hexagonal, and octagonal shapes. We will deeply discuss the below in code.

Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 5,
borderRadius: 5.0,
rotate: 70.0,
boxShadows: [
PolygonBoxShadow(color: Colors.black, elevation: 7.0),
PolygonBoxShadow(color: Colors.blue, elevation: 5.0)
],
child: Container(
child: Image.network(
"https://images.unsplash.com/photo-1508672019048-805c876b67e2?ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8dHJhdmVsfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.cover,
),
),
)),

We will make a container widget. In this widget, we will add ClipPolygon() widget. Inside, we will add sides was five for pentagonal shape, borderRadius was five, rotate was 70 degrees and boxShadows. It’s child property, we will add Container and it’s child property, we will add an image network. When we run the application, we ought to get the screen’s output like the underneath screen capture.

Pentagonal Shape

Next, we will create the same method as above. In ClipPolygon(), sides were six for hexagonal shape, rotate was 90 degrees, and boxShadows color for shadow/elevation of the card.

Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 6,
borderRadius: 5.0,
rotate: 90.0,
boxShadows: [
PolygonBoxShadow(color: Colors.greenAccent, elevation: 4.0),
PolygonBoxShadow(color: Colors.green, elevation: 5.0)
],
child: Container(
color: Colors.black,
child: Image.network(
"https://images.unsplash.com/photo-1530789253388-582c481c54b0?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1170&q=80",
fit: BoxFit.cover,
),
),
)),

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

Hexagonal Shape

Next, we will create the same method as above. In ClipPolygon(), sides were eighth for octagonal shape, rotate was 90 degrees, and boxShadows color for shadow/elevation of the card.

Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 8,
borderRadius: 5.0,
rotate: 90.0,
boxShadows: [
PolygonBoxShadow(color: Colors.black, elevation: 1.0),
PolygonBoxShadow(color: Colors.grey, elevation: 5.0)
],
child: Container(
color: Colors.black,
child: Image.network(
"https://images.unsplash.com/photo-1493863641943-9b68992a8d07?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGhvdG9ncmFwaGVyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.cover,
),
),
)),

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

Octagonal Shape

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_polygon_clipper_demo/splash_screen.dart';
import 'package:polygon_clipper/polygon_clipper.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Splash(),
);
}
}

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
backgroundColor: Colors.green[300],
automaticallyImplyLeading: false,
title: Text("Flutter Polygon Clipper Demo"),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 5,
borderRadius: 5.0,
rotate: 70.0,
boxShadows: [
PolygonBoxShadow(color: Colors.black, elevation: 7.0),
PolygonBoxShadow(color: Colors.blue, elevation: 5.0)
],
child: Container(
child: Image.network(
"https://images.unsplash.com/photo-1508672019048-805c876b67e2?ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8dHJhdmVsfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.cover,
),
),
)),
Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 6,
borderRadius: 5.0,
rotate: 90.0,
boxShadows: [
PolygonBoxShadow(color: Colors.greenAccent, elevation: 4.0),
PolygonBoxShadow(color: Colors.green, elevation: 5.0)
],
child: Container(
color: Colors.black,
child: Image.network(
"https://images.unsplash.com/photo-1530789253388-582c481c54b0?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1170&q=80",
fit: BoxFit.cover,
),
),
)),
Container(
padding: EdgeInsets.all(30.0),
child: ClipPolygon(
sides: 8,
borderRadius: 5.0,
rotate: 90.0,
boxShadows: [
PolygonBoxShadow(color: Colors.black, elevation: 1.0),
PolygonBoxShadow(color: Colors.grey, elevation: 5.0)
],
child: Container(
color: Colors.black,
child: Image.network(
"https://images.unsplash.com/photo-1493863641943-9b68992a8d07?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGhvdG9ncmFwaGVyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.cover,
),
),
)),
],
),
));
}
}

Conclusion:

In the article, I have explained the basic structure of the Polygon Clipper in a flutter; you can modify this code according to your choice. This was a small introduction to Polygon Clipper 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 Polygon Clipper in your flutter projects. We will show you what the Introduction is?. Show constructor and attributes of the Polygon Clipper. Make a demo program for working Polygon Clipper, and it shows a pentagonal, hexagonal, octagonal shape and inside a network image using Polygon clippers in your flutter application. 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 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.


Explore Spinning Animation In Flutter

0

Animation is an intricate procedure in any mobile application. Despite its intricacy, Animation improves the client experience to another level and gives a rich user interaction. Because of its extravagance, animation turns into a basic piece of present-day mobile applications. Flutter structure perceives the significance of Animation and gives a straightforward and natural system to develop a wide range of animations.

In this blog, we will be Explore Spinning Animation In Flutter. We will implement a demo program and make a spinning animation without using any plugin in your flutter applications.

Table Of Contents::

Introduction

Code Implement

Code File

Conclusion



Introduction:

The below demo video shows how to make a spinning animation in a flutter. It shows how the spinning animation will work without using any plugin in your flutter applications. When the code is successfully run, we will show four rectangle boxes that will rotate clockwise that is a spinning animation, and the user will stop/play the animation when pressing the floating action button. It will be shown on your device.

Demo Module :


How to implement code in dart file :

You need to implement it in your code respectively:

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

First, we will create an AnimationController and add a _controller variable is equal to the AnimationController() method. In this method, we will add the duration for five seconds and vsync was this. Also, adding reverse animation was false.

late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 5),
vsync: this,
)..repeat(reverse: false);

We will create an animation with the value of type “double” and an _animation variable is equal to the CurvedAnimation() method. In the method, we will add a parent as _controller and the curve was linear.

late final Animation<double> _animation = CurvedAnimation(
parent: _controller,
curve: Curves.linear,
);

We will add dispose() method. In this method, we will add _controller.dispose().

@override
void dispose() {
_controller.dispose();
super.dispose();
}

In the body, we will add RotationTransition() widget. In this widget, we will add turns was _animation variable. It’s child property, we will add padding, and it’s child property we will add four Containers with height, width, colors, and box-shape was a rectangle.

RotationTransition(
turns: _animation,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Container(
child: Wrap(
children: [
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.amber, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.green, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.indigo, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.red, shape: BoxShape.rectangle),
),
],
),
),
),
),

We will create a FloatingActionButton(). In this button, we will add a stop icon and onPressed method. In this method, we will add if _controller isAnimating then stop the animation and else start the animation.

floatingActionButton: FloatingActionButton(
child: Icon(Icons.stop),
onPressed: () {
if (_controller.isAnimating) {
_controller.stop(); // Stop the animation
} else {
_controller.repeat(); // Start the animation
}
},
),

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

Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_spinning_animation_dem/splash_screen.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: Splash());
}
}

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 5),
vsync: this,
)..repeat(reverse: false);

late final Animation<double> _animation = CurvedAnimation(
parent: _controller,
curve: Curves.linear,
);

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Flutter Spinning Animation Demo'),
),
body: Center(
child: RotationTransition(
turns: _animation,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Container(
child: Wrap(
children: [
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.amber, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.green, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.indigo, shape: BoxShape.rectangle),
),
Container(
width: 140,
height: 120,
decoration: BoxDecoration(
color: Colors.red, shape: BoxShape.rectangle),
),
],
),
),
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.stop),
onPressed: () {
if (_controller.isAnimating) {
_controller.stop(); // Stop the animation
} else {
_controller.repeat(); // Start the animation
}
},
),
);
}
}

Conclusion:

In the article, I have explained the basic structure of the Spinning Animation in a flutter; you can modify this code according to your choice. This was a small introduction to Spinning Animation 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 Spinning Animation in your flutter projects. We will show you what the Introduction is?. Make a demo program for working on Spinning Animation without using any third-party plugins. In this blog, we have examined the Spinning Animation of the flutter app. I hope this blog will help you in the comprehension of Spinning Animation 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 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.


Password Strength Checker In Flutter

0

Flutter just intrigued me with the pleasant UI stuff you could do effectively, and obviously, it permits you to create for both platforms simultaneously. The focal reason for existing is to construct the application out of widgets. It portrays how your application view should look with their present setup and state. When you modify the code, the widget rebuilt its depiction by computing the contrast between the past and current widget to decide the negligible changes for rendering in the UI of the application.

In this blog, we will explore the Password Strength Checker In Flutter. We will implement a demo program and create a Password Strength Checker without using any third-party plugins in your flutter applications.

Table Of Contents ::

Introduction

Code Implement

Code File

Conclusion



Introduction:

The below demo video shows how to create a password strength checker in a flutter. It shows how the password strength checker will work without using any third-party plugins in your flutter applications. When the user enters the password on the text field, then they will show your password was strong, weak, great, and not acceptable, etc. Also, the linear progress bar was shown with different colors. It will be shown on your device.

Demo Module :


How to implement code in dart file :

You need to implement it in your code respectively:

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

First, we will create a late String _password variable, the double _strength variable is equal to zero, and the String _displayText variable is equal to the text ‘Please enter a password.’

late String _password;
double _strength = 0;
String _displayText = 'Please enter a password'

Now, we will add RegExp for number and letter

RegExp numReg = RegExp(r".*[0-9].*");
RegExp letterReg = RegExp(r".*[A-Za-z].*");

In the body, we will add the TextField() method. In this method, we will add onChanged navigate to _checkPassword(value). We will deeply describe it below. Also, we will add obscureText was true, hintText was ‘Password’.

TextField(
onChanged: (value) => _checkPassword(value),
obscureText: true,
decoration: const InputDecoration(
border: OutlineInputBorder(), hintText: 'Password',
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.teal),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.teal),
),),
),

In the body, we will add the LinearProgressIndicator widget. In this widget, we will add a value that was _strength variable. It will change colors according to _strength variable conditions.

LinearProgressIndicator(
value: _strength,
backgroundColor: Colors.grey[300],
color: _strength <= 1 / 4
? Colors.red
: _strength == 2 / 4
? Colors.yellow
: _strength == 3 / 4
? Colors.blue
: Colors.green,
minHeight: 15,
),

Now, we will add text was _displayText variable and add ElevatedButton() widget. In this widget, we will add the onPressed method. The button will be enabled in this method if the password strength is medium or beyond and add text ‘Continue’.

Text(
_displayText,
style: const TextStyle(fontSize: 18),
),
const SizedBox(
height: 50,
),
ElevatedButton(
onPressed: _strength < 1 / 2 ? null : () {},
child: const Text('Continue'))

Now, we will deeply describe _checkPassword(value):

We will add _password variable was equal to value. trim().

_password = value.trim();

If the password was empty and add it inside the setState() method. In this method, _strength was equal to zero and _displayText was ‘Please enter your password.’

if (_password.isEmpty) {
setState(() {
_strength = 0;
_displayText = 'Please enter you password';
});
}

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

Password Empty

If the password was 6 characters less than in length, then it was weak, and add it inside the setState() method. In this method, _strength was equal to 1/4 and _displayText was ‘Your password is too short’.’

else if (_password.length < 6) {
setState(() {
_strength = 1 / 4;
_displayText = 'Your password is too short';
});
}

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

Password Short

If the password was 6 characters to less than 8 characters in length, then it was acceptable but not strong, and add it inside the setState() method. In this method, _strength was equal to 2/4 and _displayText was ‘Your password is acceptable but not strong.’

else if (_password.length < 8) {
setState(() {
_strength = 2 / 4;
_displayText = 'Your password is acceptable but not strong';
});
}

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

Password is Acceptable but not Strong

If the password was greater than equal to 8 characters in length, and but doesn’t contain both letters and digit characters, then it was strong, and add it inside the setState() method. In this method, _strength was equal to 3/4 and _displayText was ‘Your password is strong.’

if (!letterReg.hasMatch(_password) || !numReg.hasMatch(_password)) {
setState(() {
// Password length >= 8
// But doesn't contain both letter and digit characters
_strength = 3 / 4;
_displayText = 'Your password is strong';
});
}

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

Password Strong

If the password was greater than equal to 8 characters in length, and Password contains both letters and digit characters, then it was great, and add it inside the setState() method. In this method, _strength was equal to 1 and _displayText was ‘Your password is great.’

else {
// Password length >= 8
// Password contains both letter and digit characters
setState(() {
_strength = 1;
_displayText = 'Your password is great';
});
}

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

Password Great

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_password_strength/splash_screen.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
// Hide the debug banner
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: Splash(),
);
}
}

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

@override
State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
late String _password;
double _strength = 0;

RegExp numReg = RegExp(r".*[0-9].*");
RegExp letterReg = RegExp(r".*[A-Za-z].*");

String _displayText = 'Please enter a password';

void _checkPassword(String value) {
_password = value.trim();

if (_password.isEmpty) {
setState(() {
_strength = 0;
_displayText = 'Please enter you password';
});
} else if (_password.length < 6) {
setState(() {
_strength = 1 / 4;
_displayText = 'Your password is too short';
});
} else if (_password.length < 8) {
setState(() {
_strength = 2 / 4;
_displayText = 'Your password is acceptable but not strong';
});
} else {
if (!letterReg.hasMatch(_password) || !numReg.hasMatch(_password)) {
setState(() {
// Password length >= 8
// But doesn't contain both letter and digit characters
_strength = 3 / 4;
_displayText = 'Your password is strong';
});
} else {
// Password length >= 8
// Password contains both letter and digit characters
setState(() {
_strength = 1;
_displayText = 'Your password is great';
});
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text('Flutter Password Strength Checker Demo'),
),
body: Padding(
padding: const EdgeInsets.all(30),
child: Column(
children: [
TextField(
onChanged: (value) => _checkPassword(value),
obscureText: true,
decoration: const InputDecoration(
border: OutlineInputBorder(), hintText: 'Password',
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.teal),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.teal),
),),
),
const SizedBox(
height: 30,
),
// The strength indicator bar
LinearProgressIndicator(
value: _strength,
backgroundColor: Colors.grey[300],
color: _strength <= 1 / 4
? Colors.red
: _strength == 2 / 4
? Colors.yellow
: _strength == 3 / 4
? Colors.blue
: Colors.green,
minHeight: 15,
),
const SizedBox(
height: 20,
),

// The message about the strength of the entered password
Text(
_displayText,
style: const TextStyle(fontSize: 18),
),
const SizedBox(
height: 50,
),
// This button will be enabled if the password strength is medium or beyond
ElevatedButton(
onPressed: _strength < 1 / 2 ? null : () {},
child: const Text('Continue'))
],
),
));
}
}

Conclusion:

In the article, I have explained the basic structure of the Password Strength Checker in a flutter; you can modify this code according to your choice. This was a small introduction to Password Strength Checker 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 Password Strength Checker in your flutter projects. We will show you what the Introduction is?. Make a demo program for working Password Strength Checker without using any third-party plugins. In this blog, we have examined the Password Strength Checker of the flutter app. I hope this blog will help you in the comprehension of the Password Strength Checker 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 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: Verify Email and Reset Password in Flutter

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


Draggable GridView In Flutter

0

Draggable GridView is a regular mobile application connection. As the user presses now and again called touch and holds on a widget, another widget appears under the user’s finger, and the user draggable the widget to the last region and conveyances it. On multitouch devices, different draggable can happen at the same time because that there can be various pointers in touch with the devices immediately.

In this article, we will explore the Draggable GridView In Flutter. We will implement a draggable grid view demo program and create a draggable of the GridViewItems using the flutter_draggable_gridview package in your flutter applications.

Table Of Contents::

Draggable GridView

Constructor

Properties

Implementation

Code Implement

Code File

Conclusion



Draggable GridView:

Draggable GridView expands the convenience of the GridView widget in Flutter and offers you the chance of making a reorder of the GridViewItems clear by Draggable. It is too easy to even consider executing and superb to use.

Demo Module :

This demo video shows how to create a draggable grid view in a flutter. It shows how the draggable grid view will work using the flutter_draggable_gridview package in your flutter applications. It shows draggable interaction where the user long/touch presses on a choice of item and then drags it to the picture using the draggable technique. Something like a grid view with draggable can change the position both horizontally and vertically. It will be shown on your device.

Constructor:

To utilize DraggableGridViewBuilder, you need to call the constructor underneath:

const DraggableGridViewBuilder({
Key? key,
required this.gridDelegate,
required this.listOfWidgets,
required this.dragCompletion,
this.isOnlyLongPress = true,
this.dragFeedback,
this.dragChildWhenDragging,
this.dragPlaceHolder,
this.scrollDirection = Axis.vertical,
this.reverse = false,
this.controller,
this.primary,
this.physics,
this.shrinkWrap = false,
this.padding,
this.addAutomaticKeepAlives = true,
this.addRepaintBoundaries = true,
this.addSemanticIndexes = true,
this.cacheExtent,
this.semanticChildCount,
this.dragStartBehavior = DragStartBehavior.start,
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.restorationId,
this.clipBehavior = Clip.hardEdge,
})

In the above Constructor, all fields marked with @required must not be empty.

Properties:

There are some properties of DraggableGridViewBuilder are:

  • > listOfWidgets: This property is used to [listOfWidgets] will show the widgets in Gridview.builder.
  • > isOnlyLongPress: This property is used to accept ‘ true’ and ‘false’.
  • > dragFeedback: This property is used to you can set this to display the widget when the widget is being dragged.
  • > dragChildWhenDragging: This property is used to you can set this to display the widget at dragged widget original place when the widget is being dragged.
  • > dragPlaceHolder: This property is used to you can set this to display the widget at the drag target when the widget is being dragged.
  • > dragCompletion: This property is used to you have to set this callback to get the updated list.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:
flutter:
sdk: flutter
flutter_draggable_gridview:

Step 2: Import

import 'package:flutter_draggable_gridview/flutter_draggable_gridview.dart';

Step 3: Add the assets

Add assets to pubspec — yaml file.

assets:
- assets/

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

How to implement code in dart file :

You need to implement it in your code respectively:

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

We will create a Stateful widget and the respective State class has to use with DragFeedback, DragPlaceHolder, DragCompletion.

class MyHomePageState extends State<MyHomePage>
with DragFeedback, DragPlaceHolder, DragCompletion {
}

We will create a list of strings of an image that is equal to a List. generate().

static List<String> listOfImages =
List.generate(12, (index) => 'assets/${index + 1}.jpeg');

Now, we will create a listOf Widgets that are equal to the List. generate(). In bracket, inside we will add listOfImages.length (index), then return a Container widget. In this widget, we will add padding and its child property, we will add an Image. asset(). In bracket, we will add listOfImages[index] and Boxfit is cover.

List<Widget> listOfWidgets = List.generate(
listOfImages.length,
(index) => Container(
padding: EdgeInsets.only(
left: 4.0,
right: 4.0,
top: 8.0,
),
child: Image.asset(
listOfImages[index],
fit: BoxFit.cover,
),
),
);

In the body, we will add DraggableGridViewBuilder() widget. In this widget, we will add gridDelegate was SliverGridDelegateWithFixedCrossAxisCount(). Also add crossAxisCount was 2 and childAspectRatio. We will add listOfWidgets, dragCompletion, isOnlyLongPress, dragFeedback and dragPlaceHolder.

DraggableGridViewBuilder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 3),
),
listOfWidgets: listOfWidgets,
dragCompletion: this,
isOnlyLongPress: false,
dragFeedback: this,
dragPlaceHolder: this,
),

Now, widget feedback is used to can set this to display the widget when the widget is being dragged. We will return the container, it’s child property we will add items. child with width and height.

@override
Widget feedback(List<Widget> list, int index) {
var item = list[index] as Container;
return Container(
child: item.child,
width: 200,
height: 150,
);
}

Now, PlaceHolderWidget will use to show at drag target, when the widget is being dragged. We will return PlaceHolderWidget, it’s child property we will add a Container with white color.

@override
PlaceHolderWidget placeHolder(List<Widget> list, int index) {
return PlaceHolderWidget(
child: Container(
color: Colors.white,
),
);
}

This method, onDragAccept is used to you have to set this callback to get the updated list.

@override
void onDragAccept(List<Widget> list) {

}

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

Final Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_draggable_gridview/flutter_draggable_gridview.dart';
import 'package:flutter_draggable_gridview_dem/splash_screen.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.green,
),
home: Splash()
);
}
}

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

final String title;

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

class MyHomePageState extends State<MyHomePage>
with DragFeedback, DragPlaceHolder, DragCompletion {
static List<String> listOfImages =
List.generate(12, (index) => 'assets/${index + 1}.jpeg');
List<Widget> listOfWidgets = List.generate(
listOfImages.length,
(index) => Container(
padding: EdgeInsets.only(
left: 4.0,
right: 4.0,
top: 8.0,
),
child: Image.asset(
listOfImages[index],
fit: BoxFit.cover,
),
),
);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.cyan[200],
automaticallyImplyLeading: false,
title: Text(
widget.title,
),
),
body: DraggableGridViewBuilder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 3),
),
listOfWidgets: listOfWidgets,
dragCompletion: this,
isOnlyLongPress: false,
dragFeedback: this,
dragPlaceHolder: this,
),
);
}

@override
Widget feedback(List<Widget> list, int index) {
var item = list[index] as Container;
return Container(
child: item.child,
width: 200,
height: 150,
);
}

@override
PlaceHolderWidget placeHolder(List<Widget> list, int index) {
return PlaceHolderWidget(
child: Container(
color: Colors.white,
),
);
}

@override
void onDragAccept(List<Widget> list) {
}
}

Conclusion:

In the article, I have explained the basic structure of the Draggable GridView in a flutter; you can modify this code according to your choice. This was a small introduction to Draggable GridView 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 Draggable GridView in your flutter projects. We will show you what the Draggable GridView is?. Show constructor and properties of the Draggable GridView. Make a demo program for working Draggable GridView, and it shows draggable interaction where the user long/touch presses on a choice of item and then drags it to the picture using the draggable technique. Something like a grid view with draggable can change the position both horizontally and vertically in your flutter application. 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 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.


Implement Tooltip In Flutter

0

A tooltip shows a useful message when users hover, tap, or focus on a component. In Flutter, you can utilize a built-in widget named Tooltip to make tooltips effortlessly. It widget turns out to be extremely valuable when the UI of the application is too thick to even think about showing all the data at once on the screen, in a way it essentially makes the application more open.

In this blog, we will explore the Implement Tooltip In Flutter. We will see how to implement a demo program and we will see how to use Tooltip in your flutter applications.

Tooltip class – material library – Dart API
A material design tooltip. Tooltips provide text labels that help explain the function of a button or other user…api. flutter.dev

Table Of Contents::

Tooltip

Constructor

Properties

Code Implement

Code File

Conclusion



Tooltip:

A tooltip is a material design class in Flutter that gives text marks to clarify the functionality of a button or UI action. All in all, it is utilized to show extra data when the user moves or focuses over a specific widget. It expands the availability of our application. Assuming we wrap the widget with it, it is exceptionally valuable when the user long presses the widget because, all things considered, it shows up as a floating label.

There are two different ways to execute the Tooltip in a widget, the first is by utilizing the actual widget and the alternate way is restricted to certain widgets like IconButton, FloatingActionButton, and so forth which give tooltip as a property that thusly takes in a string as a parameter.

Demo Module ::

The above demo video shows how to use Tooltip in a flutter. It shows how Tooltip will work in your flutter applications. It shows when the user tap log pressed on the image, then shows a popup message. It will be shown on your device.

Constructor:

To utilize Tooltip, you need to call the constructor underneath:

const Tooltip({
Key? key,
required this.message,
this.height,
this.padding,
this.margin,
this.verticalOffset,
this.preferBelow,
this.excludeFromSemantics,
this.decoration,
this.textStyle,
this.waitDuration,
this.showDuration,
this.child,
})

In the above Constructor, all fields marked with @required must not be empty.

Properties:

There are some properties of Tooltip are:

  • > child: This property is utilized to decide the widget for which the tooltip must be shown.
  • > decoration: This property with the assistance of decoration property background color, border (Shape), of the tooltip can be controlled.
  • > excludeFormSemantics: This property is used to take in boolean as a parameter, and by default it is false. It controls whether the tooltip’s message should be added to the semantic tree or not.
  • > height: This property is used to determine the height of the tooltip. It takes in double value as a parameter.
  • > margin: This property is used to determine the space around the tooltip. It takes EdgeInsetsGeometry as the parameter.
  • > message: This property is used to take a string value as the parameter to display the text in the tooltip.
  • > padding: This property is used to also take EdgeInsetsGeometry as the parameter to determine the space between the border and the main content of the tooltip.
  • > preferBelow: This property is used to control whether to display the tooltip on the widget or below that by taking a boolean as the parameter. By default, it is set to true.
  • > showDuration: This property is used to determine the time in seconds for which the tooltip should be displayed.
  • > textStyle: This property is used to take care of the styling of the message in the tooltip such as font size or color.
  • > verticalOffset: This property is utilized to control the vertical distance between the tooltip and the widget.
  • > waitDuration: This property is utilized to control the time after which the tooltip will be made apparent once the user floats over the widget of presses it for over one second.

How to implement code in dart file :

You need to implement it in your code respectively:

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

In the body, we will add a Center widget. In this widget, we will add the Tooltip() widget. Inside the widget, we will add a message that means it takes a string value as the parameter to display the text in the tooltip and it is a required property so must not be empty. Next, we will add paddingmargindecoration with color and border-radius.

Center(
child: Tooltip(
message: 'FlutterDevs is a protruding flutter app development company with an extensive '
'in-house team of 30+ seasoned professionals who know exactly what you need '
'to strengthen your business across various dimensions.',
padding: const EdgeInsets.all(30),
margin: const EdgeInsets.only(top: 30, left:30,right: 30),
decoration: BoxDecoration(
color: Colors.blueAccent.withOpacity(0.6),
borderRadius: BorderRadius.circular(22)),
textStyle: const TextStyle(
fontSize: 15,
fontStyle: FontStyle.italic,
color: Colors.white),
child: SizedBox(
width: 320,
height: 150,
child: Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
),
)))

We will add a textStyle means it takes care of the styling of the message in the tooltip such as font size or color. In child property, we will add the SizedBox widget. In this widget, we will add width, height, and its child property, we will add an image. When we run the application, we ought to get the screen’s output like the underneath screen capture.

Final Output

Code File:

import 'package:flutter/material.dart';
import 'package:flutter_tooltips_demo/splash_screen.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Splash(),
);
}
}

class MyHomePage extends StatefulWidget {


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

class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blueAccent.withOpacity(0.6),
automaticallyImplyLeading: false,
title: Text('Flutter Tooltip Demo'),
),
body: Center(
child: Tooltip(
message: 'FlutterDevs is a protruding flutter app development company with an extensive '
'in-house team of 30+ seasoned professionals who know exactly what you need '
'to strengthen your business across various dimensions.',
padding: const EdgeInsets.all(30),
margin: const EdgeInsets.only(top: 30, left:30,right: 30),
decoration: BoxDecoration(
color: Colors.blueAccent.withOpacity(0.6),
borderRadius: BorderRadius.circular(22)),
textStyle: const TextStyle(
fontSize: 15,
fontStyle: FontStyle.italic,
color: Colors.white),
child: SizedBox(
width: 320,
height: 150,
child: Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
),
))),
);
}
}

Conclusion:

In the article, I have explained the basic structure of the Tooltip in a flutter; you can modify this code according to your choice. This was a small introduction to Tooltip 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 Tooltip in your flutter projects. We will show you what the Tooltip is?. Show constructor and properties of the Tooltip. Make a demo program for working Tooltip. It shows when the user long-press the widget, then shows a popup message in your flutter application. 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 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

Related: Using SharedPreferences in Flutter

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


RouteAware In Flutter

0

The most ideal situation when you create an application that gets delivered is that it’s a prompt achievement and users love it and use it precisely how you expected. The truth is dislike that, and you will require each piece of information accessible to see how users utilize your item.

In this blog, we will explore RouteAware In Flutter. We will see how to implement a demo program and show how to use RouteAware to screen navigation in your flutter applications.

Table Of Contents::

RouteAware

Methods

Code Implement

Conclusion



RouteAware:

An interface for objects that know about their present Route. This is utilized with RouteObserver to make a widget mindful of changes to the Navigator’s meeting history.

Demo Module ::

The above demo video shows how to use RouteAware in a flutter. It shows how RouteAware will work in your flutter applications. It shows when the user navigates between two screens. When HomePage is loaded, didPush of HomePage is called. At the point when we tapped on the button, the first didPushNext of HomePage got called and afterward, our SecondPage got delivered and didPush of SecondPage got called. At the point when we tapped on back from SecondPage, the HomePage’s didPopNext got called and afterward, SecondPage got poped and didPop of SecondPage got called. And afterward, the means were again repeated. It will be shown on your device.

Methods:

RouteAware class gives the accompanying methods which we can expand:

  • > didPop(): In this method, when we pop the current screen, the didPop method is called.
  • > didPopNext(): In this method, on the off chance that you have extended HomePage with RouteAware, and in case SecondPage is popped so HomePage is noticeable now, didPopNext is called. As such, this strategy is considered when the top screen is popped off and the current screen is apparent.
  • > didPush(): In this method, this is called when the current screen or route has been pushed into the navigation stack!
  • > didPushNext(): In this method, when we push SecondPage from HomePage, didPushNext is called. In other words, this method is called when a new screen/route is pushed from the current screen and the current screen is no longer visible.

How to implement code in dart file :

You need to implement it in your code respectively:

To start with, make a variable of RouteObserver in main.dart

final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();

Inside your, MaterialApp you need to set navigatorObservers and pass our variable into it!. Then, our main. dart will look like this:

import 'package:flutter/material.dart';
import 'package:flutter_route_aware_demo/splash_screen.dart';

void main() => runApp(MyApp());
final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Splash(),
navigatorObservers: [routeObserver],
);
}
}

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

Now will be to extend RouteAware so that you can override the different methods! Also, inside the initState() of HomePage, subscribe to the route.

@override
void initState() {
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
routeObserver.subscribe(this, ModalRoute.of(context)!);
});
super.initState();
}

Override the methods. In the body, we will add the Column widget. In this widget, we will add an image and ElevatedButton(). We are just overriding all the methods available and navigating to our next page onClick of our ElevatedButton().

import 'package:flutter/material.dart';
import 'package:flutter_route_aware_demo/second_page.dart';
import 'main.dart';

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

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

class _HomePageState extends State<HomePage> with RouteAware {
@override
void didPush() {
print('HomePage: Called didPush');
super.didPush();
}

@override
void didPop() {
print('HomePage: Called didPop');
super.didPop();
}

@override
void didPopNext() {
print('HomePage: Called didPopNext');
super.didPopNext();
}

@override
void didPushNext() {
print('HomePage: Called didPushNext');
super.didPushNext();
}

@override
void initState() {
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
routeObserver.subscribe(this, ModalRoute.of(context)!);
});
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.cyan,
automaticallyImplyLeading: false,
title: Text('Flutter RouteAware Demo'),
),
body: Center(
child:Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset("assets/logo.png",width: 300,),
SizedBox(height: MediaQuery.of(context).size.height*0.25,),
ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: TextStyle(fontSize: 20),
minimumSize: Size.fromHeight(40),
primary: Colors.cyan,
),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SecondPage(),
),
),
child: Text("Home Page",)
),
],
),
),
),
);
}
}

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

All same things can be done for the second_page.dart. In the body, we will add the text ”Flutter Dev’s” and wrap to it’s Center widget.

import 'package:flutter/material.dart';

import 'main.dart';

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

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

class _SecondPageState extends State<SecondPage> with RouteAware {
@override
void didPush() {
print('SecondPage: Called didPush');
super.didPush();
}

@override
void didPop() {
print('SecondPage: Called didPop');
super.didPop();
}

@override
void didPopNext() {
print('SecondPage: Called didPopNext');
super.didPopNext();
}

@override
void didPushNext() {
print('SecondPage: Called didPushNext');
super.didPushNext();
}

@override
void initState() {
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
routeObserver.subscribe(this, ModalRoute.of(context)!);
});
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.cyan,
title: Text('Second Page'),
),
body: Center(
child: Text(
"Flutter Dev's",
style: TextStyle(fontSize: 35.0),
),
),
);
}
}

When we run the application, we ought to get the console final output like the underneath.

Launching lib/main.dart on ONEPLUS A5010 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
Debug service listening on ws://127.0.0.1:37333/8K4tNNeL45U=/ws
Syncing files to device ONEPLUS A5010...
I/flutter (19730): HomePage: Called didPush
I/flutter (19730): HomePage: Called didPushNext
I/flutter (19730): SecondPage: Called didPush
I/flutter (19730): HomePage: Called didPopNext
I/flutter (19730): SecondPage: Called didPop
I/flutter (19730): HomePage: Called didPushNext
I/flutter (19730): SecondPage: Called didPush
I/flutter (19730): HomePage: Called didPopNext
I/flutter (19730): SecondPage: Called didPop
I/flutter (19730): HomePage: Called didPushNext
I/flutter (19730): SecondPage: Called didPush
I/flutter (19730): HomePage: Called didPopNext
I/flutter (19730): SecondPage: Called didPop

Conclusion:

In the article, I have explained the basic structure of RouteAware in a flutter; you can modify this code according to your choice. This was a small introduction to RouteAware 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 RouteAware in your flutter projects. We will show you what RouteAware is?. Show the methods of RouteAware. Make a demo program for working RouteAware. 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.

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 Deep Links – A unique way!

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


Cupertino Scrollbar In Flutter

0

At whatever point you will code for building anything in Flutter, it will be inside a widget. The focal intention is to build the application out of widgets. It portrays how your application view should look with their present design and state.

In Flutter, scrollable widgets (ListView, GridView, and so on) have no scrollbar by default. A scrollbar shows a user how long a view is. It shows how far the user has scrolled from the top limit and lets the person in question rapidly leap to a specific point.

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

CupertinoScrollbar class – Cupertino library – Dart API
An iOS-style scrollbar. To add a scrollbar to a ScrollView, simply wrap the scroll view widget in a CupertinoScrollbar…api.flutter.dev

Table Of Contents::

Introduction

Constructor

Properties

Code Implement

Code File

Conclusion



Introduction:

CupertinoScrollbar Widget is an iOS-style Scrollbar. A Scrollbar is essentially used to scroll information in a versatile screen and it demonstrates what part of a Scrollable Widget is apparent.

Naturally, the CupertinoScrollbar Widget will stay draggable and it likewise utilizes PrimaryScrollController. If the child ScrollView is limitlessly long, the RawScrollbar won’t be painted. For this situation, the scrollbar can’t precisely address the general area of the apparent region or compute the exact delta to apply while dragging the thumb or tapping on the track.

Demo Module :

The above demo video shows how to use a Cupertino Scrollbar Widget in a flutter. It shows how the Cupertino Scrollbar Widget will work in your flutter applications. It shows when the code successfully runs, then the user slides the screen up and down, and the Cupertino scrollbar will show was a vertical line/thumb. It will be shown on your devices.

Constructor:

To utilize CupertinoScrollbar, you need to call the constructor underneath:

const CupertinoScrollbar({
Key? key,
required Widget child,
ScrollController? controller,
bool isAlwaysShown = false,
double thickness = defaultThickness,
this.thicknessWhileDragging = defaultThicknessWhileDragging,
Radius radius = defaultRadius,
this.radiusWhileDragging = defaultRadiusWhileDragging,
ScrollNotificationPredicate? notificationPredicate,
})

In the above Constructor, all fields marked with @required must not be empty.

Properties:

There are some properties of CupertinoScrollbar are:

  • Key: This property is used to control if it’s should be replaced.
  • Child: This property is used to the widget below this widget in the tree. Child Property will have only one child. To allocate multiple users needs to make use of Row Widget or Column Widget and wrap a child in it.
  • controller: This property is utilized to execute Scrollbar dragging. Assuming a ScrollController is passed, scrollbar dragging will be empowered on the given ScrollController. A stateful precursor of this CupertinoScrollbar needs to deal with the ScrollController and either pass it to a scrollable relative or utilize a PrimaryScrollController to share it.
  • isAlwaysShown: This property is utilized as a bool information type and it shows whether the Scrollbar ought to consistently be apparent. When false, the scrollbar will be displayed during scrolling and will fade out in any case. At the point when true, the scrollbar will consistently be noticeable and never fade out. The controller property should be set for this situation. It ought to be passed the pertinent Scrollable’s ScrollController.
  • > thickness: This property is used to the thickness of the scrollbar.
  • > radius: This property is used to set the shape of the scrollbar thumb (rounded corners).
  • > thicknessWhileDragging: This property is used to the thickness of the scrollbar when it’s being dragged by the user. When the user starts dragging the scrollbar, the thickness will animate from [thickness] to this value, then animate back when the user stops dragging the scrollbar.
  • > radiusWhileDragging: This property is used to the radius of the scrollbar edges when the scrollbar is being dragged by the user. When the user starts dragging the scrollbar, the radius will animate from [radius] to this value, then animate back when the user stops dragging the scrollbar.

How to implement code in dart file :

You need to implement it in your code respectively:

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

First, we will create a dummyData is equal to List generate, and in the bracket, we will add the number of count and index.

final List dummyData = List.generate(20, (index) => '$index');

In the body, we will add CupertinoScrollbar() widget. In this widget, we will add a thickness was 12, the radius was circular(10), isAlwaysShown was shown true. It’s child property, we will add ListView.builder(). Inside, we will add itemCount was dummyData.length and itemBuilder. In itemBuilder, we will add inside a Card widget(). In this widget, we will add color, add text was dummyData[index] and wrap it to its Center widget. Center widget wrap to its padding widget.

CupertinoScrollbar(
thickness: 12,
radius: Radius.circular(10),
thicknessWhileDragging: 8,
isAlwaysShown: true,
child: ListView.builder(
itemCount: dummyData.length,
itemBuilder: (context, index) => Card(
color: Colors.cyan[100],
child: Padding(
padding: const EdgeInsets.all(20),
child: Center(
child: Text(
dummyData[index],
style: TextStyle(fontSize: 30),
),
),
),
),
)),

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

Output

Code File:

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

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Splash(),
);
}
}

class HomePage extends StatelessWidget {
final List dummyData = List.generate(20, (index) => '$index');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal[200],
automaticallyImplyLeading: false,
title: Text('Flutter Cupertino Scrollbar Demo'),
),
body: CupertinoScrollbar(
thickness: 12,
radius: Radius.circular(10),
thicknessWhileDragging: 8,
isAlwaysShown: true,
child: ListView.builder(
itemCount: dummyData.length,
itemBuilder: (context, index) => Card(
color: Colors.cyan[100],
child: Padding(
padding: const EdgeInsets.all(20),
child: Center(
child: Text(
dummyData[index],
style: TextStyle(fontSize: 30),
),
),
),
),
)),
);
}
}

Conclusion:

In the article, I have explained the basic structure of the Cupertino Scrollbar in a flutter; you can modify this code according to your choice. This was a small introduction to Cupertino Scrollbar 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 Cupertino Scrollbar in your flutter projects. We will show you what the Introduction is?. Show constructor and properties of the Cupertino Scrollbar. Make a demo program for working Cupertino Scrollbar. It shows when the user slides the screen up and down, then the Cupertino scrollbar will show was a vertical line/thumb. in your flutter application. 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 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: Cupertino Timer Picker In Flutter

Related: Cupertino Popup Surface In Flutter

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