Google search engine
Home Blog Page 27

SwitchListTile Widget In Flutter

0

In Flutter, to build any application, we start with widgets. The structure block of flutter applications. Widgets depict what their view ought to resemble given their present setup and state. It incorporates a text widget, row widget, column widget, container widget, and some more.

Every component on a screen of the Flutter application is a widget. The screen’s perspective totally relies on the widgets’ decision and sequence used to build the application. What’s more, the structure of the code of an application is a tree of widgets.

In this article, we will explore SwitchListTile Widget In Flutter. We will also implement a demo program, describe properties, and use them in your flutter applications.

Table Of Contents::

Flutter

SwitchListTile

Properties

Code Implementation

Code File

Conclusion



Flutter :

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

To begin with, you’ll need the necessary information on Flutter, Git, and GitHub. If you are new to flutter, you can get started by reading the official documentation on flutter. Dev.

Flutter – Beautiful native apps in record time
Paint your app to life in milliseconds with Stateful Hot Reload. Use a rich set of fully-customizable widgets to build…flutter. dev

SwitchListTile :

ListTile with a Switch. At the end of the day, a switch with a mark. It is likewise a Widget that has no capacity state. Need to control the state through stateful parent widgets.https://www.youtube.com/embed/0igIjvtEWNU?feature=oembedDemo Video

OnChanged is considered when the condition of the Switch changes. The callback boundary is bool, and the genuine methods it is chosen. False methods are unchecked. Value property Indicates if to empower, control the condition of the Switch by controlling this. We can click and can slide too.

Properties :

The following are the basic properties of the SwitchListTile:

  • > value: In this property to initialize whether this Switch is selected. True means checked, false means unchecked.
  • > onChanged: In this property, when dragging, the callback changes state /when opening and closing.
  • > activeColor: In this property, the background color of the button when the value is true. Then, the color was changed.
  • > activeTrackColor: In this property, when selected, the color of the slide was changed.
  • > activeThumbImage: In this property, the picture of the slider when selected.
  • > inactiveThumbImage: In this property, the picture of the slider when unchecked.
  • > title: In this property, title Typical is Text.
  • > subtitle: In this property, subtitles Below the title is typically Text.
  • > inactiveThumbImage: In this property, the image on the slider when the value is false. If inactiveThumbColor is also set, the inactiveThumbImage will prevail.
  • > secondary: In this property, one thing on the left side.

How to implement code in dart file :

You need to implement it in your code respectively:

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

SwitchListTile only title set

In this switchListTile, we will use only the title and the title can take any widget, but it is generally going to be a Text widget.

Card(
color: Colors.white,
child: SwitchListTile(
title: Text('Flutter Devs',style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w800,
fontSize: 20
),
),
value: _flutter,
activeColor: Colors.red,
inactiveTrackColor: Colors.grey,
onChanged: (bool value) {
setState(() {
_flutter = value;
});
},
),
),

We will wrap SwitchListTil() on the Card widget, add active color was red, inactive track color was grey. We will make a bool variable and call it on value and onChanged method.

bool _flutter = false;
SwitchListTile adds image and subtitle.

We will add an image and subtitle; the image will be shown in the leading position, and subtitles will show smaller text below the title.

Card(
color: Colors.white,
child: SwitchListTile(
title: Text('Flutter Devs',style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w800,
fontSize: 20
),
),
value: _flutter,
activeColor: Colors.red,
inactiveTrackColor: Colors.grey,
onChanged: (bool value) {
setState(() {
_flutter = value;
});
},
secondary: Image.asset("assets/devs.jpg",),
subtitle: Text('Software Company',style: TextStyle(
color: Colors.blueGrey[600],
),
),
),
),

We will add an image on the secondary method, then run the code image on your devices.

SwitchListTile slider position

We will change the slider positioned on the contolAffinity method. In this method, you will be set your slider positioned.

controlAffinity: ListTileControlAffinity.leading,

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

Output Video

This video shows how to create a SwitchLisTtile in a flutter and shows how SwitchLisTile will work in your flutter applications using properties, and then they will be shown on your device.

Code File :

import 'package:flutter/material.dart';


class SwitchListTileDemo extends StatefulWidget {
@override
_SwitchListTileDemoState createState() => _SwitchListTileDemoState();
}

class _SwitchListTileDemoState extends State<SwitchListTileDemo> {

bool _flutter = false;

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white24,
appBar: AppBar(
title: Text('Flutter SwitchListTile Demo'),
centerTitle: true,
automaticallyImplyLeading: false,
),
body: Center(
child: Card(
color: Colors.white,
child: SwitchListTile(
title: Text('Flutter Devs',style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w800,
fontSize: 20
),
),
value: _flutter,
activeColor: Colors.red,
inactiveTrackColor: Colors.grey,
onChanged: (bool value) {
setState(() {
_flutter = value;
});
},
secondary: Image.asset("assets/devs.jpg",),
subtitle: Text('Software Company',style: TextStyle(
color: Colors.blueGrey[600],
),
),
controlAffinity: ListTileControlAffinity.trailing,
),
),
),
);
}
}

Conclusion :

In the article, I have explained the SwitchListTile widget in a flutter; you can modify this code according to your choice. This was a small introduction to SwitchListTile 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 SwitchListTile widget in your flutter projects. We will show you what is SwitchListTile, some property using in SwitchListTile, and make a demo program for working SwitchListTile in your flutter applications, 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.

find the source code of the Flutter SwitchListTile Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Slidable Tile In Flutter

The flutter_slidable plugin adds a component rich slider widget to your project. Sliders like this are frequently observed in scrollable records. The Gmail application is a remarkable model, in which sliding list things offer a critical efficiency upgrade.

This plugin is packed with highlights and prepared for use, yet also profoundly adjustable if necessary. This plugin was working with iOSAndroidWeb, and Linux.

In this article, we will explore the Slidable In Flutter. We will also implement a swipe demo to either right or left on the tile using the flutter_slidable package in your flutter applications.

flutter_slidable | Flutter Package
A Flutter implementation of the slidable list item with directional slide actions that can be dismissed. Slidable is now a…pub.dev

Table Of Contents::

Slidable

Features

Implementation

Code Implement

Code File

Conclusion



Slidable

Slidable in an application can be utilized to play out a wide scope of tasks with simply a straightforward swipe to one or the other right or left on the tile. It makes the UI very easy to understand and recoveries a ton of time doing trifling tasks that can be riotous and repetitive to tasks whenever done in alternate manners. In this article, we will investigate the way toward planning a Slidable for your application.

We will build a basic application with tiles that swiped left to right archives and share option on the tile and when the swiped right to left erases and more option on the tile.

Demo Module ::

This video shows how to create a slidable in a flutter and show how to slidable will work when swiped left to right the tile and when the swiped right to left the tile in your flutter applications using flutter_slidable package, and then they will be shown on your device.

Features

  • Acknowledges essential (left/top) and secondary (right/base) widget records as slide actions.
  • > Can be excused.
  • Four implicit action panes
  • Two built-in slide action widgets
  • Built-in dismiss animation
  • Easily create custom layouts and animations
  • Closes when a slide action has been tapped (overridable)
  • Closes when the nearest Scrollable starts to scroll (overridable)
  • Option to disable the slide effect easily.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

flutter_slidable: ^latest version

Step 2: Import

import 'package:flutter_slidable/flutter_slidable.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

Go through a StatefulWidget to set the landing page for the application that would later hold the tiles that can be swiped one or the other way to perform undertakings allowed.

SlidableController _slidableController;

Go through the SlidableController to set the slides for the application. It tends to be finished by the utilization of either Slidable Constructor or Slidable. Builder Constructor.

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

import 'package:flutter/material.dart';

class HomeModal {
const HomeModal(
this.index,
this.titles,
this.subtitle,
this.color,
);

final int index;
final String titles;
final String subtitle;
final Color color;
}

Then, create a list on slidable_screen.dartfile, and the name called items are equal to List. generate().

final List<HomeModal> items = List.generate(
11,
(i) => HomeModal(
i,
_position(i),
_subtitle(i),
_avatarColor(i),
),
);

In this HomeModal, we will add an index, title, subtitle, and avatar color.

Now, we will define the body part of the app

OrientationBuilder(
builder: (context, orientation) => _buildList(
context,
orientation == Orientation.portrait
? Axis.vertical
: Axis.horizontal),
),

We will use OrientationBuilder for portrait mode and landscape mode. In this builder function, there was a widget _buildList(). We will explore this widget below.

Widget _buildList(BuildContext context, Axis direction) {
return ListView.builder(
scrollDirection: direction,
itemBuilder: (context, index) {
final Axis slidableDirection =
direction == Axis.horizontal ? Axis.vertical : Axis.horizontal;
var item = items[index];
if (item.index < 5) {
return _slidableWithLists(context, index, slidableDirection);
} else {
return _slidableWithDelegates(context, index, slidableDirection);
}
},
itemCount: items.length,
);
}

In this widget, we will use ListView.builder(). In this builder, we will add direction, itemCount, and itemBuilder. If the item.index is less than 5 then return _slidableWithLists() widget and else the item.index is greater than 5 then return _slidableWithDelegates() widget.

Let’s deep explore _slidableWithLists() widget

Widget _slidableWithLists(
BuildContext context, int index, Axis direction) {
final HomeModal item = items[index];
return Slidable(
key: Key(item.titles),
controller: _slidableController,
direction: direction,
dismissal: SlidableDismissal(
child: SlidableDrawerDismissal(),
onDismissed: (actionType) {
_showSnackBar(
context,
actionType == SlideActionType.primary
? 'Dismiss Archive'
: 'Dimiss Delete');
setState(() {
items.removeAt(index);
});
},
),
actionPane: _actionPane(item.index),
actionExtentRatio: 0.20,
child: direction == Axis.horizontal
? VerticalList(items[index])
: HorizontalList(items[index]),
actions: <Widget>[
IconSlideAction(
caption: 'Archive',
color: Colors.blue,
icon: Icons.archive,
onTap: () => _showSnackBar(context, 'Archive'),
),
IconSlideAction(
caption: 'Share',
color: Colors.indigo,
icon: Icons.share,
onTap: () => _showSnackBar(context, 'Share'),
),
],
secondaryActions: <Widget>[
IconSlideAction(
caption: 'More',
color: Colors.grey.shade200,
icon: Icons.more_horiz,
onTap: () => _showSnackBar(context, 'More'),
closeOnTap: false,
),
IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () => _showSnackBar(context, 'Delete'),
),
],
);
}

In this widget, we will return Slidable(). In this method, we will add SlidableDismissal() function; when we swipe the left to right on the tile, then the tile was deleted/archived, and they will show a message on the snackbar. We will add an actions widget like IconSlideAction archive and share. Also, add secondary actions widget like IconSlideAction more and delete. There was an actionPane option in this method, and we will make a widget called _actionPane().

static Widget _actionPane(int index) {
switch (index % 4) {
case 0:
return SlidableScrollActionPane();
case 1:
return SlidableDrawerActionPane();
case 2:
return SlidableStrechActionPane();
case 3:
return SlidableBehindActionPane();

default:
return null;
}
}

All are property of Slidable; the slide actions stay behind the item while it’s sliding, called SlidableBehindActionPane. The slide actions follow the item while it’s sliding called SlidableScrollActionPane. The slide actions animate like drawers while the item is sliding called SlidableDrawerActionPane. The slide actions stretch while the item is sliding, called SlidableStrechActionPane.

Let’s deep explore _slidableWithDelegates() widget

Widget _slidableWithDelegates(
BuildContext context, int index, Axis direction) {
final HomeModal item = items[index];
return Slidable.builder(
key: Key(item.titles),
controller: _slidableController,
direction: direction,
dismissal: SlidableDismissal(
child: SlidableDrawerDismissal(),
closeOnCanceled: true,
onWillDismiss: (item.index != 10)
? null
: (actionType) {
return showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
backgroundColor: Colors.redAccent,
title: Text('Delete',style: TextStyle(color: Colors.white),),
content: Text('Item will be deleted',style: TextStyle(color: Colors.white),),
actions: <Widget>[
FlatButton(
child: Text('Cancel',style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.of(context).pop(false),
),
FlatButton(
child: Text('Ok',style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);
},
onDismissed: (actionType) {
_showSnackBar(
context,
actionType == SlideActionType.primary
? 'Dismiss Archive'
: 'Dimiss Delete');
setState(() {
items.removeAt(index);
});
},
),
actionPane: _actionPane(item.index),
actionExtentRatio: 0.20,
child: direction == Axis.horizontal
? VerticalList(items[index])
: HorizontalList(items[index]),
actionDelegate: SlideActionBuilderDelegate(
actionCount: 2,
builder: (context, index, animation, renderingMode) {
if (index == 0) {
return IconSlideAction(
caption: 'Archive',
color: renderingMode == SlidableRenderingMode.slide
? Colors.blue.withOpacity(animation.value)
: (renderingMode == SlidableRenderingMode.dismiss
? Colors.blue
: Colors.green),
icon: Icons.archive,
onTap: () async {
var state = Slidable.of(context);
var dismiss = await showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
backgroundColor: Colors.redAccent,
title: Text('Delete',style: TextStyle(color: Colors.white),),
content: Text('Item will be deleted',style: TextStyle(color: Colors.white),),
actions: <Widget>[
FlatButton(
child: Text('Cancel',style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.of(context).pop(false),
),
FlatButton(
child: Text('Ok',style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);

if (dismiss) {
state.dismiss();
}
},
);
} else {
return IconSlideAction(
caption: 'Share',
color: renderingMode == SlidableRenderingMode.slide
? Colors.indigo.withOpacity(animation.value)
: Colors.indigo,
icon: Icons.share,
onTap: () => _showSnackBar(context, 'Share'),
);
}
}),
secondaryActionDelegate: SlideActionBuilderDelegate(
actionCount: 2,
builder: (context, index, animation, renderingMode) {
if (index == 0) {
return IconSlideAction(
caption: 'More',
color: renderingMode == SlidableRenderingMode.slide
? Colors.grey.shade200.withOpacity(animation.value)
: Colors.grey.shade200,
icon: Icons.more_horiz,
onTap: () => _showSnackBar(context, 'More'),
closeOnTap: false,
);
} else {
return IconSlideAction(
caption: 'Delete',
color: renderingMode == SlidableRenderingMode.slide
? Colors.red.withOpacity(animation.value)
: Colors.red,
icon: Icons.delete,
onTap: () => _showSnackBar(context, 'Delete'),
);
}
}),
);
}

In this widget, we will return Slidable.builder(). In this method, when we swipe the left to right on the tile, the alert dialog box opens for delete/archive purposes, and they will show a message on the snackbar. We will use action delegate and secondary action delegate for IconSlideAction(). There was an actionPane option, and the same widget called _actionPane().

floatingActionButton: FloatingActionButton(
backgroundColor: _fabColor,
onPressed: null,
child: _rotationAnimation == null
? Icon(Icons.add,color: Colors.white,)
: RotationTransition(
turns: _rotationAnimation,
child: Icon(Icons.add,color: Colors.white,),
),
),

Then, we will add FloatingActionButton(). In this button, we will add rotationAnimation; when we swipe left to right and right to left, then the floating button icon and color will be changed.

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

Final Output

Code File

https://gist.github.com/ShaiqAhmedkhan/449013f1df309c5773028eb8ab971c2a#file-slidable-dart

Conclusion:

In the article, I have explained the Slidable architecture in a flutter; you can modify this code according to your choice. This was a small introduction to Slidable 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 Slidable in your flutter projects. We will show you what is slidable, some features using in slidable, and make a demo program for working slidable, and show when swiped left to right archives and share option on the tile and when the swiped right to left deletes and more option on the tiles in your flutter applications, So please try it.

❤ ❤ Thanks for reading this article ❤❤https://giphy.com/embed/lD76yTC5zxZPG/twitter/iframe


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

Clap 👏 If this article helps you.

find the source code of the Flutter Slidable Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Explore Slivers In Flutter

0

A sliver is a part of a scrollable region that you can characterize to act exceptionally. You can utilize slivers to accomplish custom scrolling over impacts, for example, versatile scrolling over. Making scrollable substance in Flutter is exceptionally basic whether you’re attempting to pin widgets or make parallax impacts. Slivers give an incredible method to oversee how various widgets inside a format act as the user scrolls up and down.

In this article, we will Explore Slivers In Flutter. We will also implement a demo program, describe properties and their types of slivers, and how to use them in your flutter applications.

Table Of Contents::

Slivers

How to use slivers?

SliverAppBar

SliverAppBar Properties

SliverPersistentHeader

SliverFixedExtentList

SliverList

SliverGrid

Code File

Conclusion



Slivers

Sliver is a part of the scrollable zone which is utilized to accomplish a custom scrolling over impact. As such, the sliver widget is a cut of the viewport. We can actualize the implementation of the scrollable perspectives, for example, ListView, GridView utilizing slivers.

It is a lower-level interface that gives superb control over executing a scrollable region. It is valuable while scrolling over enormous numbers of children’s widgets in a scrollable zone. As they depend on the viewport, it can change their shape, size, and extent dependent on a few events and offset

Flutter gives a few sorts of slivers, some of them are given underneath:

  • > SliverAppBar
  • > SliverPersistentHeader
  • > SliverFixedExtentList
  • > SliverList
  • > SliverGrid

Demo Module ::

This video shows how to create Slivers in a flutter and show how to using slivers to making scrollable layouts in your flutter applications, and then they will be shown on your device.

How to use slivers?

It is to note that the sliver’s segments’ entirety should be put inside a CustomScrollView consistently. From that point forward, we can consolidate the list of slivers to make the custom scrollable region.

CustomScrollView in Flutter is a scroll see that permits us to make different scrolling over impacts, for example, grids, lists, and extending headers. It has a sliver property where we can pass a list of widgets that incorporate SliverAppBar, SliverFixedExtentList, SliverList, and SliverGrid, and so on.

SliverAppBar

SliverAppBar is a material design app bar in Flutter that incorporates with a CustomScrollView. By and large, we utilized it as the principal offspring of CustomScrollView. It can shift in height and buoy over the other widget of the scroll view. It permits us to make an application bar with different scrolling over impacts.

SliverAppBar(
title: Text('Flutter Slivers Demo',style:
TextStyle(fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white),),
backgroundColor: Color(0xFFEDF2F8),
expandedHeight: 200,
flexibleSpace: FlexibleSpaceBar(
background: Image.network(
"https://images.unsplash.com/photo-1603785608232-44c43cdc0d70?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDY4fEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.cover),
),
),

In this SliverAppBar, we will add title, expandedHeight, and flexibleSpace. When we run the application, we ought to get the screen’s UI like the underneath screen capture.

SliverAppBar Output

Properties of SliverAppBar

The following are the basic properties of the SliverAppBar:

  • > actions: This property is utilized to make widgets right of the appBar title. For the most part, it is an iconButton that speaks to regular operations.
  • > title: This property is utilized to characterize the title to the SliverAppBar. It is like the AppBar title to give the name of the application.
  • > leading: This property is utilized to characterize a widget left to the title. For the most part, it is utilized to put the Menu Drawer widget.
  • > backgroundColor: This property is utilized to characterize a background color to the sliver app bar.
  • > bottom: This property is utilized to make space for the lower part of the title, where we can characterize any widget as indicated by our necessities.
  • > expandedHeight: This property is utilized to determine the most extreme height of the application bar that can be extended while scrolling. It must be characterized in a double value.
  • > floating: This property decides if the application bar will be noticeable or not when the user scrolls towards the application bar.
  • > flexibleSpace: This property is utilized to characterize a widget which is stacked behind the toolbar and the tab bar. Its height is equivalent to the application bar’s general height.

SliverPersistentHeader

A sliver whose size fluctuates when the sliver is scrolled to the edge of the viewport inverse the sliver’s GrowthDirection. In the typical instance of a CustomScrollView with no focused sliver, this sliver will shift its size when scrolled to the viewport’s leading edge.

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

return SliverPersistentHeader(
pinned: true,
floating: false,
delegate: Delegate(backgroundColor, _title),
);

Create a Delegate class extend with SliverPersistentHeaderDelegate{}

class Delegate extends SliverPersistentHeaderDelegate {
final Color backgroundColor;
final String _title;

Delegate(this.backgroundColor, this._title);

@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
color: backgroundColor,
child: Center(
child: Text(
_title,
style: TextStyle(
color: Colors.white,
fontSize: 25,
),
),
),
);
}

@override
double get maxExtent => 80;

@override
double get minExtent => 50;

@override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}

In this SliverPersistentHeader, we will add title and backgroundColor. When we run the application, we ought to get the screen’s UI like the underneath screen capture.

SliverPersistentHeader Output

SliverFixedExtentList

SliverFixedExtentList is a sliver that holds numerous children with a similar fundamental axis extent in a one-dimensional array or linear array. It is more productive than SliverList because there is no compelling reason to perform layouts on its children to acquire the main-axis extent. It doesn’t permit a gap between its children. It requires every child to have the SliverConstraints.crossAxisExtent in the cross axis and the itemExtent property on the main-axis.

SliverFixedExtentList(
itemExtent: 70,
delegate: SliverChildListDelegate([
_buildFixedList(Colors.cyan, "Cyan"),
_buildFixedList(Colors.green, "Green"),
_buildFixedList(Colors.orange, "Orange"),
_buildFixedList(Colors.amberAccent, "AmberAccent"),
_buildFixedList(Colors.blueGrey, "Blue Grey"),
]),
),

In this SliverFixedExtentList, we will use itemExtent and delegate. In delegate, we will call a SliverChildListDelegate() function. When we run the application, we ought to get the screen’s UI like the underneath screen capture.

SliverFixedExtentList Output

SliverList

SliverList is a sliver that puts the children in a linear array or one-dimensional array. It takes a delegate parameter to give the things in the list so they will scroll into view. We can indicate the children’s list utilizing a SliverChildListDelegate or build them with a SliverChildBuilderDelegate.

SliverList(
delegate: SliverChildListDelegate([
Container(
margin: EdgeInsets.all(24),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Add Name', style: TextStyle(fontSize: 22)),
_buildName(),
SizedBox(height: 16),
RaisedButton(
child: Text('Submit'),
onPressed: _submit,
),
],
),
),
)
]),
),

In this SliverList, we will add TextFormField with validation and RaisedButton(). When we run the application, we ought to get the screen’s UI like the underneath screen capture.

SliverList Output

SliverGrid

SliverGrids places the children in a two-dimensional course of action. It likewise utilizes a delegate to indicate the children or an express list like the SliverList. Yet, it has extra arranged to the cross-axis measurement on a grid.

SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
childAspectRatio: 1.5
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
padding: EdgeInsets.all(8),
color: _randomColor(index),
child: Center(
child: Text(
_name[index],
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white,
fontSize: 20),
),
),
);
},
childCount: _name.length
),
)

In this SliverGrid, we will enter any name on TextFormField, then press the submit button, and the name is shown on below gridView with random colors. When we run the application, we ought to get the screen’s UI like the underneath screen capture.

SliverGrid Output

Code File

https://gist.github.com/ShaiqAhmedkhan/29de62988180c81e28c04df0cf058301#file-slivers_demo-dart

Conclusion:

In the article, I have explained some properties and types of Slivers in a flutter; you can modify this code according to your choice. This was a small introduction to Slivers 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 Slivers in your flutter projects. We will show the slivers, some properties using in slivers, and make a demo program for working slivers, and show how to using slivers to making scrollable layouts in your flutter applications, 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.

find the source code of the Flutter Slivers Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Chip Widgets In Flutter

0

Flutter widgets are built using a modern framework that takes inspiration from React. We have learned before that everything in Flutter is a widget. 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 like with their present design and state. When you adjusted the code, the widget rebuilt its portrayal by calculating the distinction between the past and current widget to decide the insignificant changes for delivering in the application’s UI.

In this article, we will explore the Chip Widgets In Flutter. We will also implement a demo program, describe properties and their types, and how to use them in your flutter applications.

Table Of Contents::

Chip Widget

Properties

Features

Types

Code File

Conclusion



Chip Widget

Chips are conservative components that speak to quality, text, entity, or action. Providing a non-invalid onDeleted callback will make the chip incorporate a button for erasing the chip. Its progenitors must incorporate MaterialMediaQueryDirectionality, and MaterialLocalizations. Regularly these widgets are given by MaterialApp and Scaffold. The label and clipBehavior contentions must not be invalid.

It speaks to complex elements in small blocks, for example, a contact. Contact chips may minimally speak to contact data. Chips can be utilized for different kinds of elements, including free-form text, predefined text, rules, or contacts. Chips may likewise contain icons.

Diagram

First, We will create a basic chip widget in flutter

Widget _buildChip(String label, Color color) {
return Chip(
labelPadding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.white70,
child: Text(label[0].toUpperCase()),
),
label: Text(
label,
style: TextStyle(
color: Colors.white,
),
),
backgroundColor: color,
elevation: 6.0,
shadowColor: Colors.grey[60],
padding: EdgeInsets.all(8.0),
);
}

}

We will create a _buildChip() widget, In this widget, we will return a Chip, and in this method, we will use an avatar and label property.

chipList() {
return Wrap(
spacing: 6.0,
runSpacing: 6.0,
children: <Widget>[
_buildChip('Gamer', Color(0xFFff6666)),
_buildChip('Hacker', Color(0xFF007f5c)),
_buildChip('Developer', Color(0xFF5f65d3)),
_buildChip('Racer', Color(0xFF19ca21)),
_buildChip('Traveller', Color(0xFF60230b)),
],
);
}

We will create the chipList() method and call _buildChip() widget on this method and Wrap it. Now, run the code and get the final output on your devices.

Chip Widget Output

Properties

Let’s see some of its properties:

  • > label: This property is required; it acknowledges any widget simultaneously; mostly, it is a great idea to have a Text widget representing the name of any entity, action, and so forth.
  • > avatar: This property was, It acknowledges any widget and can be utilized to show pictures, the underlying letters of any entity, action, and so forth
  • > backgroundColor: This property indicated the background color of the chip when it is unselected and empowered.
  • > labelStyle: This property was utilized to apply any TextStyle to the label.
  • > labelPadding: This property was added some padding around the label.
  • > elevation: This property was acknowledged as the double value and used to elevate the chip.
  • > shadowColor: This property was color to the shadow of the chip when elevation is set.
  • > deleteIcon: This property was utilized to show the delete icon. This will be just obvious when onDeleted is set.
  • > onDeleted: This property was a callback when the delete icon is squeezed inside the chip.
  • > deleteIconColor: This property was color to be set for delete icon.
  • > deleteButtonTooltipMessage: This property was set as a message to show up on the delete icon’s tooltip.
  • > shape: This property can be utilized to offer shapes to the border of the chip.

Features

  • The Chips widget Value property can be bound to a dataset of legitimate qualities, for instance, Email Addresses, Hobbies, Skillset, Categories, and the sky is the limit from there. You can add new values, yet these new values won’t be added to the dataset.
  • It goes about as a search/autocomplete widget. When you begin composing in the Chips widget, it triggers the choice of values from the dataset and compares the character’s values.
  • Permit Only Select (Default: false) — If Allow Only Select is set to valid, Chips will confine adding values other than in the choice. As a matter of default, there is no limitation. In any case, note that these new values won’t be added to the dataset.
  • Max Size (Default: 0) — By default, there is no restriction on the number of chips to add. If it is set to valid after Max Size arrives at the input box to add more, it will be covered up and indicated again after a portion of the components is erased.
  • Chip thing class name property from the styles tab can be utilized to apply styles for singular things of the Chip.
  • Class names can be entered (with no condition), these classes will be applied to all the chips.
  • Runtime Functionality: You can explore between the chip things utilizing the console both ways keys. Likewise, utilizing the erase/delete keys, the Chip thing can be Deleted.

Types

1. Action Chips

Action Chips

Action chips can be utilized to summon some activity on primary substance. It can not be disabled since it isn’t required, then it ought not even to be accessible to users.

ActionChip(
elevation: 8.0,
padding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.redAccent,
child: Icon(Icons.mode_comment,color:
Colors.white,size: 20,),
),
label: Text('Message'),
onPressed: () {
_key.currentState.showSnackBar(SnackBar(
content: Text('Message...'),
));
},
backgroundColor: Colors.grey[200],
shape: StadiumBorder(
side: BorderSide(
width: 1,
color: Colors.redAccent,
)),
);

In this chip, we will use an avatar, label, shape, and onPressed(). In the onPressed method, we will add a snackbar for displaying the text. Now, run the code and output show below the video.

Action Chips Output

2. Input Chips

Input Chips

Input chips speak to a mind-boggling snippet of information, for example, a substance (individual, spot, or thing) or conversational content, in a minimal structure.

Input chips can be made selectable by setting onSelected, deletable by setting onDeleted, and pressable like a button with onPressed. They have a label, and they can have the leading symbol (see avatar) and a trailing symbol (deleteIcon). Colors and padding can be tweaked.

InputChip(
padding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.pink.shade600,
child: Text('FD'),
),
label: Text('Flutter Devs',style: TextStyle(color:
_isSelected?Colors.white:Colors.black),
),
selected: _isSelected,
selectedColor: Colors.blue.shade600,
onSelected: (bool selected) {
setState(() {
_isSelected = selected;
});
},
onDeleted: () {
},
);

In this chip, we will show onSelected and OnDeleted for only icon show. When the user taps on this chip, then the whole chip is selected. The below video shows how the Input Chips will work.

Input Chips Output

3. Filter Chips

Filter Chips

The Filter chip contains alternatives, attributes, categories with the goal that users can filter from it. You can undoubtedly replace the checkbox with a Filter chip. Filter chips consider plainly outlined and uncovered alternatives in a conservative zone.

FilterChip(
backgroundColor: Colors.tealAccent[200],
avatar: CircleAvatar(
backgroundColor: Colors.cyan,
child: Text(company.name[0].toUpperCase(),style: TextStyle(color: Colors.white),),
),
label: Text(company.name,),
selected: _filters.contains(company.name),
selectedColor: Colors.purpleAccent,
onSelected: (bool selected) {
setState(() {
if (selected) {
_filters.add(company.name);
} else {
_filters.removeWhere((String name) {
return name == company.name;
});
}
});
},
),

In this chip, we will select and unselected randomly with your multiple choices. The below video shows how the Filter Chips will work.

Filter Chips Output

4. Choice Chips

Choice Chips

The choice chip permits choosing a single chip from the rundown. It can replace different widgets that permit a single determination, like the switch button and radio button.

ChoiceChip(
label: Text(_choices[index]),
selected: _choiceIndex == index,
selectedColor: Colors.red,
onSelected: (bool selected) {
setState(() {
_choiceIndex = selected ? index : 0;
});
},
backgroundColor: Colors.green,
labelStyle: TextStyle(color: Colors.white),
);

Choice chips contain related descriptive text or categories. This chip only allows single-chip selection. The below video shows how the Choice Chips will work.

Choice Chips Outputs

Code File

import 'package:flutter/material.dart';

class ChipDemo extends StatefulWidget {

@override
State<StatefulWidget> createState() => _ChipDemoState();
}

class _ChipDemoState extends State<ChipDemo> {


GlobalKey<ScaffoldState> _key;
bool _isSelected;
List<CompanyWidget> _companies;
List<String> _filters;
List<String> _choices;
int _choiceIndex;

@override
void initState() {
super.initState();
_key = GlobalKey<ScaffoldState>();
_isSelected = false;
_choiceIndex = 0;
_filters = <String>[];
_companies = <CompanyWidget>[
CompanyWidget('CEO'),
CompanyWidget('Director'),
CompanyWidget('Manager'),
CompanyWidget('Team Leader'),
CompanyWidget('Employee'),
];
_choices = ["Software Engineer","Software Developer",
"Software Testing"];
}

@override
Widget build(BuildContext context) {
return Scaffold(
key: _key,
appBar: AppBar(
title: Text("Chip Widget In Flutter"),
centerTitle: true,
automaticallyImplyLeading: false,
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
chipList(),
_buildActionChips(),
_buildInputChips(),
Wrap(
children: companyPosition.toList(),
),
_buildChoiceChips(),

],
),
),
);
}



chipList() {
return Wrap(
spacing: 6.0,
runSpacing: 6.0,
children: <Widget>[
_buildChip('Gamer', Color(0xFFff6666)),
_buildChip('Hacker', Color(0xFF007f5c)),
_buildChip('Developer', Color(0xFF5f65d3)),
_buildChip('Racer', Color(0xFF19ca21)),
_buildChip('Traveller', Color(0xFF60230b)),
],
);
}


Widget _buildChoiceChips() {
return Container(
height: MediaQuery.of(context).size.height/4,
child: ListView.builder(
itemCount: _choices.length,
itemBuilder: (BuildContext context, int index) {
return ChoiceChip(
label: Text(_choices[index]),
selected: _choiceIndex == index,
selectedColor: Colors.red,
onSelected: (bool selected) {
setState(() {
_choiceIndex = selected ? index : 0;
});
},
backgroundColor: Colors.green,
labelStyle: TextStyle(color: Colors.white),
);
},
),
);
}

Widget _buildInputChips() {
return InputChip(
padding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.pink.shade600,
child: Text('FD'),
),
label: Text('Flutter Devs',style: TextStyle(color:
_isSelected?Colors.white:Colors.black),
),
selected: _isSelected,
selectedColor: Colors.blue.shade600,
onSelected: (bool selected) {
setState(() {
_isSelected = selected;
});
},
onDeleted: () {
},
);
}

Widget _buildActionChips() {
return ActionChip(
elevation: 8.0,
padding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.redAccent,
child: Icon(Icons.mode_comment,color: Colors.white,size: 20,),
),
label: Text('Message'),
onPressed: () {
_key.currentState.showSnackBar(SnackBar(
content: Text('Message...'),
));
},
backgroundColor: Colors.grey[200],
shape: StadiumBorder(
side: BorderSide(
width: 1,
color: Colors.redAccent,
)),
);
}

Iterable<Widget> get companyPosition sync* {
for (CompanyWidget company in _companies) {
yield Padding(
padding: const EdgeInsets.all(6.0),
child: FilterChip(
backgroundColor: Colors.tealAccent[200],
avatar: CircleAvatar(
backgroundColor: Colors.cyan,
child: Text(company.name[0].toUpperCase(),style: TextStyle(color: Colors.white),),
),
label: Text(company.name,),
selected: _filters.contains(company.name),selectedColor: Colors.purpleAccent,
onSelected: (bool selected) {
setState(() {
if (selected) {
_filters.add(company.name);
} else {
_filters.removeWhere((String name) {
return name == company.name;
});
}
});
},
),
);
}
}

Widget _buildChip(String label, Color color) {
return Chip(
labelPadding: EdgeInsets.all(2.0),
avatar: CircleAvatar(
backgroundColor: Colors.white70,
child: Text(label[0].toUpperCase()),
),
label: Text(
label,
style: TextStyle(
color: Colors.white,
),
),
backgroundColor: color,
elevation: 6.0,
shadowColor: Colors.grey[60],
padding: EdgeInsets.all(8.0),
);
}

}

class CompanyWidget {
const CompanyWidget(this.name);
final String name;
}

Conclusion:

In the article, I have explained some properties and types of Chip Widgets; you can modify this code according to your choice. This was a small introduction to Chip Widgets 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 Chip Widgets in your flutter projects. We will show the chips, some properties using in chips, and make a demo program for working chip in your flutter applications. So please try it.

❤ ❤ Thanks for reading this article ❤❤https://giphy.com/embed/d31w24psGYeekCZy/twitter/iframe


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

Clap 👏 If this article helps you.

find the source code of the Flutter Chip Widgets Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


VelocityX Animated Page View In Flutter

In my previous blog, we saw what an actually VelocityX Animated Box is and how it works using the velocity_x package. For more explanation, I would suggest you guys go through my previous blog to clear basic concepts of velocity x.

VelocityX Animated Box In Flutter
Learn How To Use VelocityX In Your Flutter Appsmedium.com

In this article, we will explore the VelocityX Animated Page View In Flutter. We will also implement a demo and use the velocity-x to create an animated box using the velocity_x package in your flutter applications.

velocity_x | Flutter Package
VelocityX is a 100% free Flutter open-source minimalist UI Framework built with Flutter SDK to make Flutter development…pub. Dev.

Table Of Contents::

Animated Page View

Implementation

Code Implement

Code File

Conclusion



Animated Page View

PageView in Flutter is a widget that shows a list of widgets like pages and images of a carousel. It deals with snapping to the following page on the off chance that you “swipe past the other half” and other truly cool stuff.

We will use the velocity_x package, and for animation, we will use VxAnimatedHeightView() widget. PageView Like most looking over family’s widgets, an approach to tune in to its status changes, our goal here is to listen to these shape changes and animated images when users swipe accordingly.

Demo Module ::

This video shows how to create an animated page view in a flutter and shows how the animated page view will work in your flutter applications using velocity-x. They will change the shape when you swipe the image. They will be shown on your device.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

velocity_x: ^latest version

Step 2: Import

import 'package:velocity_x/velocity_x.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

final Widget child = VxAnimatedHeightView<PageView>(
pageViewChild: PageView.builder(
itemCount: img.length,
controller: PageController(),
itemBuilder: (context, index) {
final String imgUrl = img.elementAt(index);
final double width = context.screenWidth;
final double height = width * calculateImg(index);
return GestureDetector(
onTap: () {
print("press img index is $index");
},
child: Image.network(imgUrl ?? "",
width: width,
height: height,
fit: BoxFit.cover,
alignment: Alignment.topCenter
),
);
},
onPageChanged: (index) {
setState(() {
_currentIndex = index;
});
},
),
itemCount: img.length,
currentPageIndex: _currentIndex,
computeAspectRadio: (index) {
return calculateImg(index);
},
notifyScroll: (scrollNotification) {},
);

We will use VxAnimatedHeightView() widget. In this widget, we will use pageview, item count, controller, and builder. We will set the current index on the setState() method.

List<String> dummyImages() {
return [
"https://images.unsplash.com/photo-1565065598196-aa15dde2cbca? ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDMxfEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1603788059192-43ee674988c0?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDE2fEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1461749280684-dccba630e2f6?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDEzMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1603785608232-44c43cdc0d70?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDY4fEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1581090124360-558a029c4148?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDEwMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1599524882167-39718267c453?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDIwMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
];
}

We will create dummy images URL in a list and create an instance named called img.

final List<String> img = dummyImages();

We will add image size and add different animation sizes when the app runs; then, they show our screen.

We create a list named called _imgMap for image size.

final List<double> _imgMap = [1.0, 0.7, 1.1, 0.9, 1.2, 0.8];

We create a calculateImg() method and return _imgMap[]

double calculateImg(int index) {
return _imgMap[index];
}

In VxAnimatedHeightView(),we will required pageviewChild, computeAspectRadio, motifyScroll, itemCount, and but not the least currentPageIndex.

VxAnimatedHeightView(
{@required this.pageViewChild,
@required this.computeAspectRadio,
this.notifyScroll,
this.itemCount,
this.currentPageIndex})
: assert(pageViewChild != null),
assert(computeAspectRadio != null),
assert(itemCount > 0);

Now we will call class VelocityXAnimatedPageView() in home_page.dartinside the lib folder.

body: VStack([
Padding(
padding: const EdgeInsets.all(18.0),
child: Center(
child: Text("Swipe image to show animated
page view",
style: TextStyle(fontSize: 16),
)
),
),
VelocityXAnimatedPageView()
]).

In the body, we will call VStack, and VStack Is the property of velocity X. In this VStack, we will add text and a class VelocityXAnimatedPageView(). Now, run the code and get the final output on your devices.

Final Output

Code File

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

class VelocityXAnimatedPageView extends StatefulWidget {
@override
_VelocityXAnimatedPageViewState createState() => _VelocityXAnimatedPageViewState();
}

class _VelocityXAnimatedPageViewState extends State<VelocityXAnimatedPageView> {
final List<double> _imgMap = [1.0, 0.7, 1.1, 0.9, 1.2, 0.8];
int _currentIndex = 0;

List<String> dummyImages() {
return [
"https://images.unsplash.com/photo-1565065598196-aa15dde2cbca?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDMxfEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1603788059192-43ee674988c0?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDE2fEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1461749280684-dccba630e2f6?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDEzMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1603785608232-44c43cdc0d70?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDY4fEo5eXJQYUhYUlFZfHxlbnwwfHx8&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1581090124360-558a029c4148?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDEwMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
"https://images.unsplash.com/photo-1599524882167-39718267c453?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDIwMXxKOXlyUGFIWFJRWXx8ZW58MHx8fA%3D%3D&auto=format&fit=crop&w=500&q=60",
];
}

double calculateImg(int index) {
return _imgMap[index];
}

@override
Widget build(BuildContext context) {
final List<String> img = dummyImages();
if (img.isEmpty) {
return Container();
}

final Widget child = VxAnimatedHeightView<PageView>(
pageViewChild: PageView.builder(
itemCount: img.length,
controller: PageController(),
itemBuilder: (context, index) {
final String imgUrl = img.elementAt(index);
final double width = context.screenWidth;
final double height = width * calculateImg(index);
return GestureDetector(
onTap: () {
print("press img index is $index");
},
child: Image.network(imgUrl ?? "",
width: width,
height: height,
fit: BoxFit.cover,
alignment: Alignment.topCenter
),
);
},
onPageChanged: (index) {
setState(() {
_currentIndex = index;
});
},
),
itemCount: img.length,
currentPageIndex: _currentIndex,
computeAspectRadio: (index) {
return calculateImg(index);
},
notifyScroll: (scrollNotification) {},
);
return child;
}
}

Conclusion:

In the article, I have explained the basic structure of a VelocityX Animated Page View using the VxAnimatedHeightView widget; you can modify this code according to your choice. This was a small introduction to VelocityX Animated Page View 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 VelocityX Animated Page View in your flutter projects. This demo program uses velocity_x packages and VxAnimatedHeightView widget in a flutter and shows how an animated page view will work in your flutter applications. 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.

find the source code of the Flutter VelocityX Animated Page View Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


VelocityX Animated Box In Flutter

0

TailwindCSS roused flutter Velocity X. It intensely utilizes expansion techniques and accompanies numerous prebuilt widgets. The AnimatedContainer will naturally animate between the old and new properties when utilizing the gave bend and duration. Invalid properties are not animated. Its child and descendants are not animated.

VelocityX is intended to be effectively introduced, and the main point was to make it significantly simpler to compose a User Interface.

In this article, we will explore the VelocityX Animated Box In Flutter. We will also implement a demo and use the velocity-x to create an animated box using the velocity_x package in your flutter applications.

velocity_x | Flutter Package
VelocityX is a 100% free Flutter open-source minimalist UI Framework built with Flutter SDK to make Flutter development…pub. dev

Table Of Contents::

Velocity X

Velocity X Widgets

Implementation

Code Implement

Code File

Conclusion



Velocity X

VelocityX lets you focus on your design, and it accompanies different widget expansions to make it responsive over the devices. A moderate Flutter structure propelled by TailwindCSS and SwiftUI for quickly building custom designs. A system that gives you all of the structure blocks you require to manufacture bespoke plans with no irritating settled styles you need to battle to wrap.

Demo Module ::

This video shows how to create an animated box in a flutter and shows how the animated box will work in your flutter applications using velocity-x. They will change the shape and color of the box. They will be shown on your device.

Velocity X Widgets

There are some popular VelocityX widgets:

  • VxTimeline
  • > VxAnimatedBox
  • > VxSwiper
  • > VxRating
  • > VxToast

Note: In this article we will describe VxAnimatedBox widget in flutter.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

velocity_x: ^latest version

Step 2: Import

import 'package:velocity_x/velocity_x.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

We will implement this screen. There was an animated container on this screen, and the shape of the container will be changed every 4 seconds—shape like rectangle, square, circle, cylinder, etc. We will use the velocity x package to animate the container and change shapes.

final random = Random();
_width = random.nextInt(350).toDouble();
_height = random.nextInt(350).toDouble();

We will create a random instance and use it.

_color = Color.fromRGBO(
random.nextInt(250),
random.nextInt(250),
random.nextInt(250),
1,
);

We will use random RGBO color when the animated container shapes change, then the color also automatically changes.

Let’s describe VxAnimatedBox() widgets

return VxAnimatedBox()
.alignCenter
.seconds(sec: 5)
.fastOutSlowIn
.width(_width + 50)
.height(_height)
.color(_color)
.withRounded(value: _radius)
.p12
.make()
.py16();

In VxAnimatedBox(), you will set box shape, height, width, transformation, duration, box-shadow, and also set a background image. We will add curves like bounceIn, easeIn, fastOutSlowIn, etc.

Now we will add a timer in the initState() method.

@override
void initState() {
super.initState();
Timer.periodic(2.seconds,
(timer) {
setState(() {});
});
}

The animation will start according to the time you put on your own free will.

Now we will call class AnimatedBoxDemo() in velocityx_animated_box.dartinside the lib folder.

Container(
child:Center(
child: (
AnimatedBoxDemo()
),
),

)

Now, run the code and get the output on your devices.

Code File

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';

import 'package:velocity_x/velocity_x.dart';


class AnimatedBoxDemo extends StatefulWidget {
@override
_AnimatedBoxDemoState createState() => _AnimatedBoxDemoState();
}

class _AnimatedBoxDemoState extends State<AnimatedBoxDemo> {
double _width,
_height,
_radius;
Color _color;

@override
void initState() {
super.initState();

Timer.periodic(2.seconds, (timer) {
setState(() {});
});
}

@override
Widget build(BuildContext context) {
final random = Random();
_width = random.nextInt(350).toDouble();
_height = random.nextInt(350).toDouble();

_color = Color.fromRGBO(
random.nextInt(250),
random.nextInt(250),
random.nextInt(250),
1,
);


_radius = random.nextInt(100).toDouble();
return VxAnimatedBox()
.alignCenter
.seconds(sec: 5)
.fastOutSlowIn
.width(_width + 50)
.height(_height)
.color(_color)
.withRounded(value: _radius)
.p12
.make()
.py16();
}
}

Conclusion :

In the article, I have explained the basic type widget of a VelocityX Animated Box; you can modify this code according to your choice. This was a small introduction to VelocityX Animated Box 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 VelocityX Animated Box in your flutter projects. This demo program uses velocity_x packages in a flutter and shows how an animated box will work in your flutter applications. In my next article, we will explore other velocity X widgets, 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.

find the source code of the Flutter VelocityX Animated Box Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Animated Bar Chart In Flutter

Flutter empowers developers to create high-quality application UIs for iOS and Android. A considerable lot of the Flutter applications being made inside at Google present a lot of information. Doing that effectively requires ordinary UI widgets, however, loads of exquisite charts.

Insights assume a significant function in our everyday life as it encourages us to comprehend information which is fundamental for people to endure. Perception of the details is significant as it encourages us to comprehend the information. Perception is a cycle of plotting and drawing different sorts of curves/charts/graphs/plots for the offered information to make it reasonable.

In this article, we will explore the Animated Bar Chart In Flutter. We will also implement a demo of the bar chart using the charts_flutter package in your flutter applications.

charts_flutter | Flutter Package
Material Design data visualization library is written natively in Dart. See the online gallery. The /example/ folder…pub.dev

Table Of Contents::

Charts

Chart Types

Implementation

Code Implement

Code File

Conclusion



Charts

Charts and Graphs are one of the significant parts of numerous applications in reality. Some genuine world applications like Medium, StackOverflow, GitHub, and so on use Graphs and Charts in countless use cases. Taking a gander at crude information can be truly disappointing and convoluted. In this way, the utilization of pictures, graphs, and charts in applications can generally give excellent experiences in the information we are working on.

Flutter being an excellent UI structure of the advanced period, gives an enormous number of choices to work with graphs and charts exquisitely. One can make some extremely incredible user encounters with Graphs and Charts utilizing Flutter with local execution. To work with charts and graphs in Flutter, we have a few choices, yet we will be mainly focusing on the bar charts in this article.

Demo Module ::

This video shows how to create a bar chart in a flutter and shows how to bar chart will work in your flutter applications with animation, and then they will be shown on your device.

Chart Types

Charts for Flutter upholds three carts types, each with a few setup choices:

  • > Bar charts: A bar chart is a method of summing up a bunch of clear cut information (nonstop information can be made absolute via auto-binning). The bar chart shows information utilizing various bars, each representing a specific class. This graph incorporates uphold for stacking a few information series, demonstrating objective lines, and delivering the bars evenly.
  • > Line Charts: line chart is a graphical portrayal of a resource’s verifiable value activity that interfaces a progression of information focus with a constant line. This is the essential kind of chart utilized in money and ordinarily portrays a security’s end costs over a long time, in this chart, including support for time series.
  • > Pie Chart: pie chart (or a circle chart) is a circular factual, realistic, separated into cuts to show mathematical extent. In a pie chart, each cut’s curve length (and thus its focal point and region) corresponds to the amount it represents.

Note: We will only describe the bar chart in flutter.

Implementation:

Step 1: Add the dependencies

=Add dependencies to pubspec — yaml file.

dependencies:

charts_flutter: ^latest version

Step 2: Import

import 'package:charts_flutter/flutter.dart'

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

Before plotting the bar-chart, we will initially set up the information. For that, we will characterize a class BarChartModel as we are plotting the bar chart demo information.

import 'package:charts_flutter/flutter.dart' as charts;

class BarChartModel {
String month;
String year;
int financial;
final charts.Color color;

BarChartModel({this.month,
this.year, this.financial,
this.color,}
);
}

After characterizing the class, we will characterize some dummy information inside a list, which we will plot in the bar-chat.

final List<BarChartModel> data = [
BarChartModel(
year: "2014",
financial: 250,
color: charts.ColorUtil.fromDartColor
(Color(0xFF47505F)),
),
BarChartModel(
year: "2015",
financial: 300,
color: charts.ColorUtil.fromDartColor
(Colors.red),
),
BarChartModel(
year: "2016",
financial: 100,
color: charts.ColorUtil.fromDartColor
(Colors.green),
),
BarChartModel(
year: "2017",
financial: 450,
color: charts.ColorUtil.fromDartColor
(Colors.yellow),
),
BarChartModel(
year: "2018",
financial: 630,
color: charts.ColorUtil.fromDartColor
(Colors.lightBlueAccent),
),
BarChartModel(
year: "2019",
financial: 1000,
color: charts.ColorUtil.fromDartColor
(Colors.pink),
),
BarChartModel(
year: "2020",
financial: 400,
color: charts.ColorUtil.fromDartColor
(Colors.purple),
),
];

In the wake of setting up the plot’s information, we will be dealing with the plot’s UI.

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

List<charts.Series<BarChartModel, String>> series = [
charts.Series(
id: "Financial",
data: widget.data,
domainFn: (BarChartModel series, _) => series.year,
measureFn: (BarChartModel series, _) => series.financial,
colorFn: (BarChartModel series, _) => series.color),
];

return _buildFinancialList(series);

}

Above code, we will define in build function method. Also, there’s a widget _buildFinancialList(), which is defined below.

Let’s declare _buildFinancialList() widget .

Widget _buildFinancialList(series) {
return _barChartList != null
? ListView.separated(
physics: NeverScrollableScrollPhysics(),
separatorBuilder: (context, index) => Divider(
color: Colors.white,
height: 5,
),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _barChartList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: MediaQuery.of(context).size.height/ 2.3,
padding: EdgeInsets.all(10),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_barChartList[index].month,
style: TextStyle(
color: Colors.black, fontSize: 22,
fontWeight: FontWeight.bold)
),
],
),
Expanded( child: charts.BarChart(series,
animate: true)
),
],
),
);
},
)
: SizedBox();
}

In the above bit of code, we utilize the BarChart() widget to plot the bar-chart, which gives us many choices to alter the graph. Different alternatives and modifications should likewise be possible in the chart utilizing the properties of this widget.

Now we will call class BarChartGraph() in bar_chart_demo.dartinside the lib folder.

Container(
child: ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
BarChartGraph(
data: data,
),
],
),
),

Now, run the code and get the output on your devices.

Bar Chart Final output

Code File

import 'package:flutter/material.dart';
import 'package:flutter_animated_bar_chart/bar_chart_graph.dart';
import 'package:flutter_animated_bar_chart/bar_chart_model.dart';
import 'package:charts_flutter/flutter.dart' as charts;


class BarChartDemo extends StatefulWidget {
@override
_BarChartDemoState createState() => _BarChartDemoState();
}

class _BarChartDemoState extends State<BarChartDemo> {

final List<BarChartModel> data = [
BarChartModel(
year: "2014",
financial: 250,
color: charts.ColorUtil.fromDartColor(Color(0xFF47505F)),
),
BarChartModel(
year: "2015",
financial: 300,
color: charts.ColorUtil.fromDartColor(Colors.red),
),
BarChartModel(
year: "2016",
financial: 100,
color: charts.ColorUtil.fromDartColor(Colors.green),
),
BarChartModel(
year: "2017",
financial: 450,
color: charts.ColorUtil.fromDartColor(Colors.yellow),
),
BarChartModel(
year: "2018",
financial: 630,
color: charts.ColorUtil.fromDartColor(Colors.lightBlueAccent),
),
BarChartModel(
year: "2019",
financial: 1000,
color: charts.ColorUtil.fromDartColor(Colors.pink),
),
BarChartModel(
year: "2020",
financial: 400,
color: charts.ColorUtil.fromDartColor(Colors.purple),
),
];


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Animated Bar Chart Demo"),
automaticallyImplyLeading: false,
centerTitle: true,
),
body: Center(
child: Container(
child: ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
BarChartGraph(
data: data,
),

],
),

),
),
);
}
}

Conclusion :

In the article, I have explained the structure of an Animated Bar Chart; you can modify this code according to your choice. This was a small introduction to Animated Bar Chart 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 Animated Bar Chart in your flutter projects. This is a demo program to use charts_flutter packages in a flutter and show how an animated bar chart will work in your flutter applications, 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.

find the source code of the Flutter Animated Bar Chart Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Animated Custom Switch In Flutter

0

Flutter, as of now, gives default animation both to android and ios. Nonetheless, on the off chance that you need to add a couple of customizations and animations to the switch, then there aren’t numerous alternatives with the default switch. Here, I will keep in touch with one of the approaches to make a customized switch and add animations.

We will focus on the most direct approach to add animations to your application. You don’t need to be a specialist in animations or animation terminology to add animations to your application.

In this article, we will explore the Animated Custom Switch In Flutter. We will also implement a demo of an animated custom switch using the simple_animations package and supercharged_package in your flutter applications.

simple_animations | Flutter Package
Simple Animation is a powerful framework to create beautiful custom animations in no time. 💪 Fully tested 📝 well…pub.dev

Table Of Contents::

Custom Switch

Properties

Implementation

Code Implement

Code File

Conclusion



Custom Switch

Custom Switch button with alluring animation made to permit you to customize colors, symbols, and other restorative substance. Deal with the widget states similarly you do with the classical material’s switch widget.

We basically characterize the animation by utilizing a MultiTrackTween (Animatable that tween multiple properties without a moment’s delay). We pass this tween into a ControlledAnimation (widget for straightforward tween-based animations).

Demo Module ::

This “form-control” acts as a switch box, but it has a cool switch animation. This video shows how to create a custom animated switch in a flutter and show how to custom switch will work in your flutter applications with custom animation, and then they will be shown on your device.

Properties

During the animation, it changes four different properties:

  • > left padding: In this property is moving from left to right,
  • > rotation: In this property is from -360° (=-2*pi) to 0° (=0pi),
  • > color: In this property, we will change color red to blue,
  • > text string: In this property is changing “off” to “on” in the middle of the animation.

Also, we need the switched state (Is the switch box currently switched?) as an input property to control the animation.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

simple_animations: ^latest version
supercharged: ^latest version

Step 2: Import

import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

On this screen, an animated custom switch when the enabling button converts red color to blue color and labels text Enable Custom Switch.

We will bind the switched input property to ControlledAnimation’s control and startPosition property:

control: switched
? CustomAnimationControl.PLAY
: CustomAnimationControl.PLAY_REVERSE,
startPosition: switched ? 1.0 : 0.0,

The switch box gets switched at whatever point it guarantees that it plays the animation forward at stops toward the end. At the point when it gets unswitched, it animates in reverse and stops toward the start.

The property startPosition indicates the underlying animation position of the widget. On the off chance that the switch box is a switch toward the starting, we need our underlying animation position toward the end (1.0 ).

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

class CustomSwitch extends StatelessWidget {
final bool switched;

CustomSwitch({this.switched});

@override
Widget build(BuildContext context) {
var tween = MultiTween<_SwitchBoxProps>()
..add(_SwitchBoxProps.paddingLeft, 0.0.tweenTo(60.0), 1.seconds)
..add(_SwitchBoxProps.color, Colors.red.tweenTo(Colors.blue), 1.seconds)
..add(_SwitchBoxProps.text, ConstantTween("OFF"), 500.milliseconds)
..add(_SwitchBoxProps.text, ConstantTween("ON"), 500.milliseconds)
..add(_SwitchBoxProps.rotation, (-2 * pi).tweenTo(0.0), 1.seconds);

return CustomAnimation<MultiTweenValues<_SwitchBoxProps>>(
control: switched
? CustomAnimationControl.PLAY
: CustomAnimationControl.PLAY_REVERSE,
startPosition: switched ? 1.0 : 0.0,
duration: tween.duration * 1.2,
tween: tween,
curve: Curves.easeInOut,
builder: _buildSwitchBox,
);
}
}

By restricting the switched state to the control, the property makes the animation instinctively pivot when the user is connecting while at the same time animating.

Presently it’s an ideal opportunity to actualize the genuine switch box widgets. The second boundary animation is a Map that contains all our tweened properties.

Let’s we will describe the _buildSwitchBox widget:

Widget _buildSwitchBox(
context, child, MultiTweenValues<_SwitchBoxProps> value) {
return Container(
decoration: _outerBoxDecoration(value.get(_SwitchBoxProps.color)),
width: 100,
height: 40,
padding: const EdgeInsets.all(3.0),
child: Stack(
children: [
Positioned(
child: Padding(
padding:
EdgeInsets.only(left: value.get(_SwitchBoxProps.paddingLeft)),
child: Transform.rotate(
angle: value.get(_SwitchBoxProps.rotation),
child: Container(
decoration:
_innerBoxDecoration(value.get(_SwitchBoxProps.color)),
width: 30,
child: Center(
child: Text(value.get(_SwitchBoxProps.text),
style: labelStyle)),
),
),
))
],
),
);
}

In this widget, we will use MultiTweenValue, transform, and two BoxDecorations are first one is_outerBoxDecoration() and second one is _innerBoxDecoration().

Let’s we will explore _innerBoxDecoration()

_innerBoxDecoration

Let’s we will explore _outerBoxDecoration()

_outerBoxDecoration

Finally, you will be run the code, and then the output comes at Custom Switch will animate at forward and reverse both.

Code File

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_custom_switch_demo/custom_switch.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';



class SwitchButton extends StatefulWidget {
@override
_SwitchButtonState createState() => _SwitchButtonState();
}

class _SwitchButtonState extends State<SwitchButton> {
bool enableSwitch = false;

void _toggle() {
setState(() {
enableSwitch = !enableSwitch;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white70,
appBar: AppBar(
title: Text("Flutter Animated Custom Switch Demo"),
centerTitle: true,
automaticallyImplyLeading: false,
),
body: GestureDetector(
onTap: _toggle,
behavior: HitTestBehavior.translucent,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Text(
"Enable Custom Switch",
textScaleFactor: 1.3,
),
),
SizedBox(height: 10,),
CustomSwitch(switched: enableSwitch),

],
),
),
),
);
}

}

Conclusion :

In the article, I have explained the structure of Animated Custom Switch; you can modify this code according to your choice. This was a small introduction to Animated Custom Switch 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 Animated Custom Switch in your flutter projects. This is a demo program to use simple animations and supercharged packages in a flutter and show how animated custom switch will work in your flutter applications, 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.

find the source code of the Flutter Animated Custom Switch Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Animated TypeWriter Box In Flutter

I generally needed to work with flawless or insane animations. I have worked with Flutter for a long time, and I was beginning to locate some new Flutter animations. Animations can assist you with build all the more outwardly engaging Flutter applications. Much the same as how you would add some basic animations to make an introduction:

  • Outwardly engaging.
  • Stand out enough to be noticed at the right spot when it is required.
  • Make it much less exhausting.

Similarly, we can use animations to make our Flutter application more magnificent and stick out.

Animations give superior experience to users. I know, and you may be realizing that Flutter has extraordinary help for Animations effortlessly of utilization. There are huge loads of incredible articles for beginning with Animations in Flutter.

In this article, I will talk about Animated TypeWriter Box In Flutter. I will show you a demo of animating a typewriter box using the simple_animations package and supercharged_package in your flutter applications.

supercharged | Flutter Package
Supercharged brings all the comfort features from languages like Kotlin to all Flutter developers.pub.dev

Table Of Contents::

TypeWriter Box

Implementation

Code Implement

Code File

Conclusion



TypeWriter Box

We will Animate the typeWriter box using PlayAnimation with the help of duration, tween, and builder. We will also animate the width of the box, text length, and cursor. Typewriter provides a builder-pattern-friendly Typewriter widget for animating text.

Demo Module ::

This video shows how to create a TypeWriter Box in a flutter and show how to typeWriter Box will work in your flutter applications with play animation, and then they will be shown on your device.

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

simple_animations: ^latest version
supercharged: ^latrst version

Step 2: Import

import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

static final boxDecoration = BoxDecoration(
color: Colors.lightBlueAccent[200],
borderRadius: BorderRadius.all
(Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.black.
withAlpha(50),
blurRadius: 15,
offset: Offset(0, 8),
spreadRadius: 5
)
]);

We will create a static BoxDecoration with box-shadow, border-radius, and color of the box.

On this screen, an animate box with light blue color and inside animate a text Flutter Devs.

Now we can write our render function. It returns a PlayAnimation widget that comes from the Simple Animations package. It can simply start an animation. It takes four parameters:

  • Duration: The property is utilized to indicate what amount of time the animation cycle should require. The time is determined in a moment or two or milliseconds and is first set to ‘0s’, which implies that the animation happens promptly. You can determine one duration or various comma-isolated durations
  • Tween: A linear interpolation between the start and finishing value. Tween is valuable on the off chance that you need to add over a range. To utilize a Tween object with an animation, consider the Tween objects animate technique and passes it to the Animation object you need to adjust.
  • Delay: It permits an animation to start execution at some point after it is applied or to seem to have started execution at some point before it is applied. The underlying worth is ‘0s’, which implies that the animation will begin to play when applied to an element.
  • Builder: It is a function that is called each casing you are animating. To improve your animation presentation, you should put all widgets not influenced by the animation into the child’s property. You get that child widget passed into the builder function.
return PlayAnimation<double>(
duration: 1600.milliseconds,
delay: 500.milliseconds,
tween: 2.0.tweenTo(300.0),
builder: (context, child, width) {
return Container(
decoration: TypeWriterBox.
boxDecoration,
width: width,
height: height,
child: typewriter(width)
? TypeWriterText("Flutter Devs")
: Container(),
);
},
);

Let’s we will describe the typewriter widget:

In this widget typewriter was double width and width was greater than 15.

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

We can implement that behavior into our TypeWriterText class:

import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';


class TypeWriterText extends StatelessWidget {
static const Type_Writer_STYLE =
TextStyle(letterSpacing: 5,
fontSize: 20, fontWeight:
FontWeight.w400,
color: Colors.white);

final String text;
TypeWriterText(this.text);

@override
Widget build(BuildContext context) {
return PlayAnimation<int>(
duration: 1000.milliseconds,
delay: 1000.milliseconds,
tween: 0.tweenTo(text.length),
builder: (context, child, textLength) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(text.substring(0, textLength),
style: Type_Writer_STYLE
),
_blinkingCursor()
],
);
});

}
}

In this TypeWriterText class, we will define const Type_Writer_STYLE, add animation for text , and _blinkingCursor() widget. We will use tween is 0.tweenTo(text.length).

Let’s explore _blinkingCursor() widget:

In this widget, we will use LoopAnimation with duration, tween, and builder. We will also return opacity.

Code File

import 'package:flutter/material.dart';
import 'package:flutter_animates_typewriter/type_writer_text.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';


class TypeWriterBox extends StatefulWidget {
static final boxDecoration = BoxDecoration(
color: Colors.lightBlueAccent[200],
borderRadius: BorderRadius.all
(Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(50),
blurRadius: 15,
offset: Offset(0, 8),
spreadRadius: 5
)
]);

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

class _TypeWriterBoxState extends State<TypeWriterBox> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text("Flutter Animates TypeWriter Box Demo"),
centerTitle: true,
automaticallyImplyLeading: false,
),
body: Center(
child: PlayAnimation<double>(
duration: 400.milliseconds,
tween: 0.0.tweenTo(80.0),
builder: (context, child, height) {
return PlayAnimation<double>(
duration: 1600.milliseconds,
delay: 500.milliseconds,
tween: 2.0.tweenTo(300.0),
builder: (context, child, width) {
return Container(
decoration: TypeWriterBox.boxDecoration,
width: width,
height: height,
child: typewriter(width)
? TypeWriterText("Flutter Devs")
: Container(),
);
},
);
},
),
),
);
}

bool typewriter(double width) => width > 15;
}

Conclusion :

In the article, I have explained the structure of Animated TypeWriter Box; you can modify this code according to your choice. This was a small introduction to Animated TypeWriter Box 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 Animated TypeWriter Box in your flutter projects. This is a demo program to use simple animations and supercharged packages in a flutter and show how animated typewriter box will work in your flutter applications, 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.

find the source code of the Flutter Animated TypeWriter Box Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Particle Animation On User Interaction In Flutter

0

Animations assume a significant function in upgrading your application’s general user experience from the visual input, motion, and up to the animations you can actually envision!. Each mobile developer wishes to include animations in their application; however, they are unsuccessful because there is a ton of complexity and many things a developer needs to learn before including animations. Much like some other items coordinated into an application, animations must be a functional element instead of only a regular stylistic theme.

Flutter has an awesome Animation library that permits you to make complex animations that can run continuously without any problem. Utilizing the traditional frameworks, you would typically need to compose complex animation controllers and designs to set the timings, tweens, and advances.

In this article, we will explore Particle Animation On User Interaction In Flutter. We will also implement a demo of particle animation using the simple_animations package in your flutter applications.

simple_animations | Flutter Package
Simple Animation is a powerful framework to create beautiful custom animations in no time. 💪 Fully tested 📝 well…pub.dev

Table Of Contents::

Introduction

Implementation

Code Implement

Particle Animation

Code File

Conclusion



Introduction

Essentially, it’s some modest “whack-a-square” execution in Flutter. The virtual square shows up for a short duration at six different places. At the point when you click one square, it will part into different particles. After an arbitrary time, they respawn once more. So essentially, it’s simply a straightforward response game.

Demo Module ::

Implementation:

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies:

simple_animations: ^latest version

Step 2: Import

import 'package:simple_animations/simple_animations.dart';
import 'package:sa_v1_migration/sa_v1_migration.dart';

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

Step 4: Enable AndriodX

Add this to your gradle.properties file:

org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

How to implement code in dart file :

You need to implement it in your code respectively:

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

For the square, we utilize a Container wrapped into a GestureDetector to route the client taps into a _hitSquare() strategy. This square container is inside a Stack alongside the particles.

We should begin by indicating to you a few codes of the square widget:

class Square extends StatefulWidget {
@override
_SquareState createState() => _SquareState();
}

class _SquareState extends State<Square> {
final List<SquareParticle> particles = [];

bool _squaresVisible = false;

@override
Widget build(BuildContext context) {
return Container(
width: 70,
height: 70,
child: _buildSquare(),
);
}

Rendering _buildSquare() {
return Rendering(
onTick: (time) => _manageParticleLife(time),
builder: (context, time) {
return Stack(
overflow: Overflow.visible,
children: [
if (_squaresVisible)
GestureDetector(onTap: () => _hitSquare(time),
child: _square()),
...particles.map((it) => it.buildWidget(time))
],
);
},
);
}

Widget _square() {
return Container(
decoration: BoxDecoration(
color: Colors.redAccent, shape: BoxShape.rectangle ),
);
}

_hitSquare(Duration time) {
_setSquareVisible(false);
Iterable.generate(50).forEach((i) => particles.add(SquareParticle(time)));
}

_manageParticleLife(Duration time) {
particles.removeWhere((particle) {
return particle.progress.progress(time) == 1;
});
}

void _setSquareVisible(bool visible) {
setState(() {
_squaresVisible = visible;
});
}

@override
void setState(fn) {
if (mounted) {
super.setState(fn);
}
}
}

Inside the_hitSquare() the strategy, we hide the square container and generate 50 particles of SquareParticle. This class likewise has a buildWidget() strategy to assemble a little square particle.

Everything is going on inside a Rendering widget. It takes a boundary onTickthat we use to deal with the particle life cycle. In our _manageParticleLife() strategy, we eliminate all particles with a finished animation.

Particle Animation

Our particle animation begins by overlaying the first square container. After some time, the particle container reduces to zero while flying an irregular way.

Square particles spread out of time and get smaller

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

We can implement that behavior into our SquareParticle class:

class SquareParticle {
Animatable tween;
AnimationProgress progress;

SquareParticle(Duration time) {
final random = Random();
final x = (100 + 200) * random.nextDouble() *
(random.nextBool() ? 1 : -1);
final y = (100 + 200) * random.nextDouble() *
(random.nextBool() ? 1 : -1);

tween = MultiTrackTween([
Track("x").add(Duration(seconds: 1),
Tween(begin: 0.0, end: x)),
Track("y").add(Duration(seconds: 1),
Tween(begin: 0.0, end: y)),
Track("scale").add(Duration(seconds: 1),
Tween(begin: 1.0, end: 0.0))
]);
progress = AnimationProgress(
startTime: time, duration:
Duration(milliseconds: 900));
}

buildWidget(Duration time) {
final animation = tween.transform(
progress.progress(time));
return Positioned(
left: animation["x"],
top: animation["y"],
child: Transform.scale(
scale: animation["scale"],
child: Container(
width: 70,
height: 70,
decoration: BoxDecoration(
color: Colors.redAccent,
shape: BoxShape.rectangle
),
),
),
);
}
}

On particle creation, we process an irregular objective position and store this data into a tween. We use MultiTrackTween (originating from Basic Animations) as we need to tween three different properties at once.

At that point, we make an AnimationProgress (originating from Basic Animations) that monitors our animation progress. We need to take care of him at the current time.

Animated tween values and the advancement are utilizing inside the buildWidget() strategy to draw a positioned and scaled Container.

Code File

https://gist.github.com/ShaiqAhmedkhan/f92c29b8343a4b18218b45a996081b9f#file-square_animation-dart

At long last, we have pleasant animation utilizing a particle system on user interaction. You will see a full code on a GitHub, and the below video shows how particle animation on user interaction will work in your flutter applications.

Final result

Conclusion :

In the article, I have explained the structure of Particle Animation On User Interaction; you can modify this code according to your choice. This was a small introduction to Particle Animation 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 Particle Animation On User Interaction in your flutter projects. This is a demo program to use a simple animation package in a flutter and show how particle animation on user interaction will work in your flutter applications, 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.

find the source code of the Flutter Particle Animation Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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