Google search engine
Home Blog Page 62

SnackBar Widget in Flutter

0

Whenever you are going to code for building anything in Flutter, it will be inside a widget. each element on the screen of the Flutter application is a widget. The screen’s perspective entirely relies on the choice and grouping of the widgets used to build the application. Also, the structure of the code of an application is a tree of widgets.

In this blog, we will understand the static and custom SnackBar widget and its functionality in the flutter. We will see in this implementation of a simple demo program on the SnackBar Widget.


Table Contents:

SnackBar Widget

Code Implementation

Code File

Conclusion

GitHub Link



SnackBar:

In Flutter the SnackBar is a widget that lightweight pop up a quick message in your app that briefly signifies the user when something happened. Using a SnackBar you pop up a message for a few seconds at the bottom of your app.

By default, the snack bar displays at the bottom of the screen, and when the specified time is completed, it will be disappeared from the screen and we can make a custom snack bar also and It contains some actions that allow the user to add or remove any action and images. SnackBar requires a Scaffold, with a Scaffold instance and your SnackBar will instantly pop up. it’s easy to get a reference of your scaffold at any point in your widget tree by using the scaffold. of function.

Demo Module :


How to implement code in dart file :

You need to implement it in your code respectively:

First, In this dart file, I have created two buttons, the first button is for showing the default SnackBar and the second one is for the custom SnackBar.I am going to introduce first the Default SnackBar.

Default SnackBar

There are two steps for displaying a SnackBar. First, you have to create a SnackBar which can be done by calling the following constructor. it is very simple to use. here is the code.final snackBar = SnackBar(content: Text(‘Yay! A DefaultSnackBar!’));
ScaffoldMessenger.of(context).showSnackBar(snackBar);

But some of our requirements are not met, by default SnackBar .so May custom SnackBar is doing it. For custom SnackBar, I have to use a Flushbar dependency. it is a very congruent dependency to design your custom SnackBar upon your choice.

First, add the dependency of the SnackBar in pubspec.yaml

another_flushbar: ^1.10.24

And then have to create a method for showing the custom SnackBar.

void showFloatingFlushbar( {@required BuildContext? context,
@required String? message,
@required bool? isError}){
Flushbar? flush;
bool? _wasButtonClicked;
flush = Flushbar<bool>(
title: "Hey User",
message: message,
backgroundColor: isError! ? Colors.red : Colors.blueAccent,
duration: Duration(seconds: 3),
margin: EdgeInsets.all(20),

icon: Icon(
Icons.info_outline,
color: Colors.white,),
mainButton: FlatButton(
onPressed: () {
flush!.dismiss(true); // result = true
},
child: Text(
"ADD",
style: TextStyle(color: Colors.amber),
),
),) // <bool> is the type of the result passed to dismiss() and collected by show().then((result){})
..show(context!).then((result) {

});
}

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

Custom SnackBar

Code File:

import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';

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

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

class _SnackBarViewState extends State<SnackBarView> {

@override
Widget build(BuildContext context) {

return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildSnackBarButton()
],
),
);
}

Widget _buildSnackBarButton() {
return Column(
children: [
Center(
child: InkWell(
onTap: (){
final snackBar = SnackBar(content: Text('Yay! A Default SnackBar!'));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: Container(
height: 40,
width: 180,
decoration: BoxDecoration(
color: Colors.pinkAccent,
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Center(
child: Text("SnackBar",
style: TextStyle(
color: Colors.white,
fontSize: 16,

),),
),

),
),
),
SizedBox(height: 10,),
Center(
child: InkWell(
onTap: (){
showFloatingFlushbar(context: context,
message: 'Custom Snackbar!',
isError: false);
// showSnackBar(
// context: context,
// message: 'Custom Snackbar!',
// isError: false);
},
child: Container(
height: 40,
width: 180,
decoration: BoxDecoration(
color: Colors.pinkAccent,
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Center(
child: Text("Custom SnackBar",

style: TextStyle(
color: Colors.white,
fontSize: 16,

),),
),

),
),
),
],
);
}
}

void showFloatingFlushbar( {@required BuildContext? context,
@required String? message,
@required bool? isError}){
Flushbar? flush;
bool? _wasButtonClicked;
flush = Flushbar<bool>(
title: "Hey User",
message: message,
backgroundColor: isError! ? Colors.red : Colors.blueAccent,
duration: Duration(seconds: 3),
margin: EdgeInsets.all(20),

icon: Icon(
Icons.info_outline,
color: Colors.white,),
mainButton: FlatButton(
onPressed: () {
flush!.dismiss(true); // result = true
},
child: Text(
"ADD",
style: TextStyle(color: Colors.amber),
),
),) // <bool> is the type of the result passed to dismiss() and collected by show().then((result){})
..show(context!).then((result) {

});
}

void showSnackBar(
{@required BuildContext? context,
@required String? message,
@required bool? isError}) {
final snackBar = SnackBar(
content: Text(
message!,
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.normal),
),
duration: Duration(seconds: 3),
backgroundColor: isError! ? Colors.red : Colors.green,
width: 340.0,
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),

action: SnackBarAction(
label: 'Undo',
textColor: Colors.white,
onPressed: () {},
),
);
ScaffoldMessenger.of(context!).showSnackBar(snackBar);
}

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Flutter SnackBar Demo:

GitHub – flutter-devs/flutter_snackbar_demo
Permalink Failed to load the latest commit information. A new Flutter project. This project is a starting point for a…github.com


From Our Parent Company Aeologic

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

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

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

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

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


Slide Transition Widget In Flutter

0

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

In this blog, we will explore the SlideTransition widget and custom Transition widget using PageRouteBuilder and its functionality in the flutter, and Cupertino Sliding Segmented Control In Flutterlso we will see how to implement this Slide transition widget step by step in this demo program.


Table Contents:

Slide Transition

Constructor

Properties

PageRoughtBuilder

Code Implementation

Conclusion

GitHub Link


Slide Transition:

In the Flutter SlideTransition is a widget that animates the position of a widget relative to its normal position and slides required a little bit more interaction by using tween, in this case, offset, and flutter widget. The translation is expressed as an Offset scaled to the child’s size. For example, an Offset with a dx of 0.25 will result in a horizontal translation of one-quarter of the width of the child.

By default, the offsets are applied in the coordinate system of the canvas (so positive x offsets move the child towards the right). If a widget direction is provided, then the offsets are applied in the reading direction, so in the right-to-left widget, positive x offsets move towards the left, and in the left-to-right widget, positive x offsets move towards the right as same applied top to bottom.

Demo Module :


Constructor:

Default Constructor for it will look like as below:

SlideTransitionWidget({
Key key,
@required Animation<Offset> position,
bool transformHitTests: true,
TextDirection textDirection,
Widget child,
});

Properties:

There are some properties of Slide Transition are:

  • > Key: This attribute key, controls how one widget replaces another widget in the tree.
  • > Animation<Offset> position: This attribute is used to define the animation that controls the position of the child. If the current value of the position animation is (dx, dy), the child will be translated horizontally by width * dx and vertically by height * dy, after applying the textDirection if available.
  • > bool transformHitTests: This attribute defines whether hit testing should be affected by the slide animation. If false, hit testing will proceed as if the child was not translated at all. Setting this value to false is useful for fast animations where you expect the user to commonly interact with the child widget in its final location and you want the user to benefit from “muscle memory”.
  • > TextDirection textDirection: This attribute will define the direction to use for the x offset described by the position. If textDirection is null, the x offset is applied in the coordinate system of the canvas so positive x offsets move the child towards the right. Now if textDirection is TextDirection.rtl, the x offset is applied in the reading direction such that x offsets move the child towards the left. So now, if textDirection is TextDirection.ltr, the x offset is applied in the reading direction such that x offsets move the child towards the right.
  • > Widget child: This attribute is used to define the widget below this widget in the tree. This widget can only have one child. To layout multiple children, let this widget’s child be a widget such as Row Widget, Column Widget, or Stack Widget, which have a children’s property, and then provide the children to that widget.

To make more custom the transition flexibly, I am using PageRouteBuilder class.

PageRouteBuilder:

A utility class for defining one-off page routes in terms of callbacks. PageRouteBuilder provides an Animation object. This Animation can be used with Tween and Curve objects to customize the transition animation. This recipe shows how to transition between routes by animating the new route into view from the bottom of the screen.

To create a custom page route transition, this recipe uses the following steps:

  • Set up a PageRouteBuilder
  • Create a Tween
  • Add an AnimatedWidget
  • Use a CurveTween
  • Combine the two Tweens

How to implement code in the dart file:

You need to implement it in your code respectively:

In the first, I have created some custom radio buttons to show animation transition types. and I have added a dependency in pubspec.yaml file for use custom radio button. using the below dependency.

pubspec. yaml:

custom_radio_grouped_button: any

Then add custom radio buttons.

CustomRadioButton(
enableShape: true,
elevation: 0,
defaultSelected: "Left",
enableButtonWrap: true,
width: 100,
autoWidth: false,
unSelectedColor: Theme.of(context).canvasColor,
buttonLables: [
"Left",
"Right",
"Top",
"Bottom",
"InOut",
"Side",

],
buttonValues: [
"Left",
"Right",
"Top",
"Bottom",
"InOut",
"Side",

],
radioButtonValue: (value) {
radioButtonItem=value.toString();
print("Value:$value");
print("radioButtonItem:$radioButtonItem");
},
selectedColor: Theme.of(context).accentColor,
),

Now implement SlideTransition Widget.

First, implement in your class with SingleTickerProviderStateMixin. to use an animation controller. Then the user needs to define the controller and animation using the below code.

Suppose you have two pages: The first page and the second page. You’re on the First page and you want to navigate to the Second page. Somewhere in the First, you will do:

AnimationController _controller;
Animation<Offset> _animation;

initState() will have a code sample as below:

@override
void initState() {
super.initState();
controller =
AnimationController(vsync:this, duration: Duration(seconds: 1));

offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0))
.animate(controller);
}

Now final I have created a class that extends PageRoughtBuilder class.

First left to right animation implementations code sample are:

class SlideLeftRoute extends PageRouteBuilder {
final Widget widget;
SlideLeftRoute({required this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return new SlideTransition(
position: new Tween<Offset>(
begin: const Offset(-1.0, 0.0),
end: Offset.zero,
).animate(animation),
child: child,
);
}
);
}

The second right to left animation implementations code sample is:

class SlideRightRoute extends PageRouteBuilder {
final Widget widget;
SlideRightRoute({required this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return new SlideTransition(
position: new Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: Offset.zero,
).animate(animation),
child: child,
);
}
);
}

The third top to bottom animation implementations code sample is:

class SlideTopRoute extends PageRouteBuilder {
final Widget widget;
SlideTopRoute({required this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return new SlideTransition(
position: new Tween<Offset>(
begin: const Offset(0.0, -1.0),
end: Offset.zero,
).animate(animation),
child: child,
);
}
);
}

The fourth bottom to top animation implementations code sample is:

class SlideBottomRoute extends PageRouteBuilder {
final Widget widget;
SlideBottomRoute({required this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return new SlideTransition(
position: new Tween<Offset>(
begin: Offset(0.0, 1.0),
end: Offset.zero,
).animate(animation),
child: child,
);
// transitionDuration:Duration(seconds: 1);
}
);
}

The fifth in and out animation implementations code samples are:class ScaleRoute extends PageRouteBuilder {
final Widget widget;

ScaleRoute({required this.widget})
: super(pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return widget;
}, transitionsBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child) {
return new ScaleTransition(
scale: new Tween<double>(
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: animation,
curve: Interval(
0.00,
0.50,
curve: Curves.linear,
),
),
),
child: ScaleTransition(
scale: Tween<double>(
begin: 1.5,
end: 1.0,
).animate(
CurvedAnimation(
parent: animation,
curve: Interval(
0.50,
1.00,
curve: Curves.linear,
),
),
),
child: child,
),
);
});
}

The six side animation implementations code sample.

class SlideSideMoveRoute extends PageRouteBuilder {
final Widget widget;
SlideSideMoveRoute({required this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionDuration: Duration(seconds: 1),
transitionsBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
Animation<Offset> custom= Tween<Offset>(
begin:Offset(1.0,1.0),end: Offset(0.0,0.0)).animate(animation);
return SlideTransition(
position: custom,
child: child);
}
);
}

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Slide Transition:

GitHub – flutter-devs/slide_transition
Contribute to flutter-devs/slide_transition development by creating an account on GitHub.github.com


From Our Parent Company Aeologic

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

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

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

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

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


RefreshIndicator In Flutter

0

In this blog, we will see the RefreshIndicator widget and its properties in the flutter. If something changes in data from API then it does not update in the app so we need to load the data again in our app. Flutter provides us a RefreshIndicator widget that can be used to update the data in the app. and We will see in this implementation of a demo program on the RefreshIndicator Widget.


Table Contents:

RefreshIndicator Widget

Code Implementation

Conclusion

GitHub Link


RefreshIndicator:

RefreshIndicator is a widget in a flutter. It is used to update the data in the app. RefreshIndicator will trigger a refresh when the list is over-scrolled. It is showing a circular progress indicator if you want something to happen, add a callback function with the onRefrence property.

This function is not given any parameters, but RefreshIndicator expects it to return a future. the even spinning indicator of refreshing will continue spinning as long as that future is pending. as the spinning end, it will call onRefresh.You can customize your callback function.

Demo Module :


Code Implementation:

How to implement code in the dart file:

First, we will create a _buildCardDesign() widget. In this widget, we will return a Container(). Inside, we will add margin and its child property, we will add ListView.builder(). We will add itemCount, shrinkWrap was true, scrollDirection was Axis. vertical and itemBuilder. In itemBuilder, we will pass BuildContext context, int index parameter, and return _buildCardView() method.

We will deeply define below the code.

Widget _buildCardDesign() {
return Container(
margin: EdgeInsets.all(5),
child: ListView.builder(
itemCount: itemCount,
shrinkWrap: true,
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return _buildCardView();
}),
);
}

We will define buildCardView() method:

We will create a _buildCardView() method. In this method, we will return Container. Inside, we will add a network image and wrap it on ClipRRect() widget. Also, we will add some text hardcoded and star icons.

Widget _buildCardView() {
return Container(
width: MediaQuery.of(context).size.width,
child: Container(
margin: EdgeInsets.all(10),
height: 100,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Container(
//color: Colors.pinkAccent,
padding: EdgeInsets.fromLTRB(10, 20, 10, 20),
child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.network(
"https://s1.1zoom.me/big0/716/Brunette_girl_Hair_Glance_Model_Colored_background_593058_1365x1024.jpg",
height: 60.0,
width: 60.0,
fit: BoxFit.cover,
),
),
//SizedBox(width: 20,),
Container(
padding: EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
"Neelu Modanwal",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
Container(
padding: EdgeInsets.only(top: 5),
child: Text(
"Your opinion matters!",
style: TextStyle(color: Colors.black, fontSize: 15),
),
),
Container(
padding: EdgeInsets.only(top: 5),
child: Text(
"Dev, do you have a moment?We'd love",
style: TextStyle(color: Colors.black, fontSize: 11),
),
),
],
),
),
Column(
children: [
Text(
"4:15 AM",
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 12),
),
SizedBox(
height: 22,
),
Container(
// height: 20,
// width: 20,
margin: EdgeInsets.only(left: 10),
//color: Colors.pinkAccent,
child: Icon(
Icons.star,
color: Colors.grey,
),
)
],
),
],
),
),
),
);
}

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

And the second one, I have implemented RefreshIndicator on the whole screen. When swiping the screen. it rendered the progress indicator and call the own propertyonRefresh.And I have increased the length of the list by one according to the number of swipes in the onRefresh function with the delay sometimes. The code snippet is given below.

RefreshIndicator(
displacement: 250,
backgroundColor: Colors.yellow,
color: Colors.red,
strokeWidth: 3,
triggerMode: RefreshIndicatorTriggerMode.onEdge,
onRefresh: () async {
await Future.delayed(Duration(milliseconds: 1500));
setState(() {
itemCount = itemCount + 1;
});
},
child: Scaffold(
backgroundColor: Color(0xff246df8),
appBar: AppBar(
title: Text('Refresh Indicator'),
backgroundColor: Color(0xff246df8),
),
body: _buildCardDesign(),
),
);

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the RefreshIndicator Demo:

GitHub – flutter-devs/swipe_refresh_by_refreshIndicator
Contribute to flutter-devs/swipe_refresh_by_refreshIndicator development by creating an account on GitHub.github.com


From Our Parent Company Aeologic

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

Trusted across industries like manufacturing, healthcare, logistics, BFSI, and smart cities, Aeologic combines innovation with deep industry expertise to deliver future-ready solutions.Feel free to connect with us
And read more articles from FlutterDevs.com.

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

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


FractionallySizedBox In Flutter

0

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

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


Table Of Contents::

Introduction

Properties

Code Implement

Code File

Conclusion

GitHub Link


Introduction:

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

Demo:


Properties :

There are some properties of the FractionallySizedBox Widget:

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

Code Implement:

How to implement code in dart file :

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

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

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

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

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

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

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

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

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

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

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

Code File:

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

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

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

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the FractionallySizedBox :

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


From Our Parent Company Aeologic

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

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

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

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

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


Material Banner In Flutter

0

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

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

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


Table Of Contents::

Introduction

Properties

Code Implement

Code File

Conclusion

GitHub Link


Introduction:

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

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

Demo:

Properties:

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

Code Implement:

How to implement code in dart file :

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

flutter upgrade

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

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

final String title;

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

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

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

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

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

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

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

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

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

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

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

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

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

backgroundColor: Colors.lightGreenAccent,

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

leading: Icon(Icons.error),

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

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

Code File:

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

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

final String title;

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

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

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the MaterialBanner :

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


From Our Parent Company Aeologic

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

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

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

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

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


Cupertino Picker In Flutter

0

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

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

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

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


Table Contents:

Cupertino Picker

Cupertino Picker Types

Code Implementation

Conclusion

GitHub Link



Cupertino Picker:

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

Domo module:


Cupertino Picker Types:

There are several modes of the picker listed here.

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

Code Implementation:

Let’s see How to implement the code

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

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

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

Home Screen

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

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

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

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

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

Cupertino Picker

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

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

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

Cupertino Date Picker

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

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

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

Cupertino Time Picker

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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


Clap 👏 If this article helps you.

GitHub Link:

find the source code of the Flutter Cupertino Picker Demo:

GitHub – flutter-devs/cupertino_picker_demo_app
Contribute to flutter-devs/cupertino_picker_demo_app development by creating an account on GitHub.github.com


From Our Parent Company Aeologic

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

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

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

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

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

Flutter 2.0 Button Cheat Sheet

0

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

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



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

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

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

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

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

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

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

An example of using the new way:

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

),

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

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

An example of it would be :

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

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


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

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

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

The styleFrom method for the same would be:

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

Shape — the new way of providing shape with ButtonStyle is

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

The styleFrom method for the same would be:

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

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

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

The styleFrom method for the same is:

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

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

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

The styleFrom method for it is the same:

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

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

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

The styleFrom method for the same is:

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

TextStyle — you can provide textstyle in ButtonStyle this way:

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

),
),

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

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

),
),

The styleFrom method for the same is:

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

),
),

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

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

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

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

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

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


Flutter App for Desktop

0

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

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


Table Contents:

Flutter

Flutter benefits

Flutter platform-specific criteria

Set Up for run application on desktop

Implementation

Conclusion

GitHub Link


Flutter :

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

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

Flutter benefits:

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

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

Flutter platform-specific criteria:

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

Set Up for run application on Desktop Platform Specific:

  1. First, you create your flutter project.

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

  • > flutter channel beta

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

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

3- And then Enable your window using this command.

  • > flutter config — enable-windows-desktop

Check below documentation

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

5- After enabling your window restart your Android studio.

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

  • > flutter create.

7- Now install visual studio go to this link.

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

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

Implementation:

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

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

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

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

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

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

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

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

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

}

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


Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

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

GitHub – flutter-devs/flutter_app_for_desktop: how to set up for run the application on desktop
Permalink Failed to load the latest commit information. A new Flutter project. This project is a starting point for a…github.com


From Our Parent Company Aeologic

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

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

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

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

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


Explore Encrypt & Decrypt Data in Flutter

0

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

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


Table Of Contents::

Encryption & Decryption

Type of Encrypt data

Code Implement

Code File

Conclusion


Introduction:

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

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

Demo module::


Type Of Encrypt data:

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

1- AES Algorithm :

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

2- Fernet Algorithm:

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

3- Salsa Algorithm:

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

Code Implementation:

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

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

  • > encrypt: ^5.0.1

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

import 'package:crypto/crypto.dart';

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

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

class EncryptData{
//for AES Algorithms

static Encrypted? encrypted;
static var decrypted;

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

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

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

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

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

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

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

Code File:

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

class HomeView extends StatefulWidget {

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

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

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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


Clap 👏 If this article helps you.

From Our Parent Company Aeologic

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

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

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

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

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

2026 Ultimate Guide to Boosting Code Style with Lint Rules in …

0

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


Table Of Contents ::

Important links

Who linting helps?

Writing new linting rules

Enable and disable linting rules

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

analysis_options.yaml

Conclusion



Important links:

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

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

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

How linting helps?:

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

Writing new linting rules:

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

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

Enable and disable linting rules:

We can easily enable and disable linting rules:

linter:

rules:
always_declare_return_types: false
annotate_overrides: true

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

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

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

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

AFTER RESOLVING ALL THE ERROR

analysis_options.yaml:

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

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

Conclusion:

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

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

🌸🌼🌸 Thank you for reading 🌸🌼🌸

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

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

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

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

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

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

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

Related: Flutter AI Agents: Building Autonomous Workflows in Mobile Apps (With Code Samples)

Related: Pin Code Fields In Flutter

Related: Code Splitting & Lazy Loading in Flutter: Speeding Up App Startup Times