Google search engine
Home Blog Page 60

YouTube Player In Flutter

0

Flutter is Google’s UI tool stash for making astounding, natively compiled iOS and Android applications from a solitary codebase. To develop any application, we start with widgets — The constructing square of flutter applications. Widgets depict what their view should take after given their current plan and state. It consolidates a text widget, row widget, column widget, container widget, and some more.

As a mobile developer, playing videos is a common task in app development. From Social Media stories to application development courses, playing videos straightforwardly inside your application is getting increasingly required.

In this article, we will explore How to play YouTube videos from the playlist in Flutter Applications? We will also implement a demo program and use the package YouTube_Player_Iframe to play videos in the flutter project.


Table Of Contents::

Introduction

Setting up Project

Code Implementation

Conclusion

GitHub Link



Introduction:

Youtube_player_iframe can play YouTube videos from a network source. Its excellence is that you don’t have to write a ton of code to implement a Youtube player with gesture support. This package supports Live Stream videos, Playlist Support (Both custom and Youtube’s playlist), supports changing playback rate, and provides default youtube web player’s skin.

Supported Platforms:

  • Android.
  • IOS.
  • Web.

Setting up Project:

Step 1: Package Used

youtube_player_iframe | Flutter Package
Flutter port of the official YouTube iFrame player API. Supports web & mobile platforms.pub.dev

Add youtube_player_iframe plugin in the dependencies in pubspec.yaml file. Then run $ flutter pub get command.

dependencies:
youtube_player_iframe: 'latest version'

Step 2: Import the package as

import 'package:youtube_player_iframe/youtube_player_iframe.dart';

Step 3: Requirements

  • Android: Set minSdkVersion 17 of your android/app/build.gradle file.
  • IOS: --ios-language swift, Xcode version >= 11
  • Web: None
For Android::
defaultConfig {
applicationId "com.example.youtubeplayer"
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

Code Implementation:

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

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

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

class _YoutubePlayerDemoState extends State<YoutubePlayerDemo> {
"Write your code here...."
}
}

2. We should provide a YouTube Player Controller to play various videos shown in a ListView; it will be ideal for putting the entirety of the video-playing-related things into its own widget.

late YoutubePlayerController _ytbPlayerController;

3. We will define “_ytbPlayerController” and ‘‘_setOrientation’’ method in initState(). YoutubePlayerController is the controller for the videos you want to play and DeviceOrientation defines the position of the device in its default orientation or in which orientation the hardware logos.

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

_setOrientation([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);

WidgetsBinding.instance!.addPostFrameCallback((_) {
setState(() {
_ytbPlayerController = YoutubePlayerController(
initialVideoId: videosList[0].youtubeId,
params: YoutubePlayerParams(
showFullscreenButton: true,
autoPlay: false,
),
);
});
});
}

4. Add the YoutubePlayerIframe widget to display video in your Flutter application.

AspectRatio(
aspectRatio: 16 / 9,
child: _ytbPlayerController != null
? YoutubePlayerIFrame(controller: _ytbPlayerController)
: Center(child: CircularProgressIndicator()),
);

5. We will write the code to create PlayList in listview and on tap of the cards new video will render on the display screen.

ListView.builder(
itemCount: videosList.length,
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
final _newCode = videosList[index].youtubeId;
_ytbPlayerController.load(_newCode);
_ytbPlayerController.stop();
},
child: 'Create your card design'

When we run the application, we get the screen’s output video like this where user can play video by selecting from the playlist(ListView).

Conclusion:

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the YouTube_Player :

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


From Our Parent Company Aeologic

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

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

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

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

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


Explore Multi-Select Items In Flutter

Flutter widget is built using a modern framework. It is like a react. In this, we start with the widget to create any application. Each component in the screen is a widget. The widget describes what his outlook should be given his present configuration and condition. Widget shows were similar to its idea and current setup and state.

Flutter automated testing empowers you to meet high responsiveness in your application as it helps in discovering bugs and various issues in your application. A Flutter is a tool for developing mobile, desktop, web applications with code & is a free and open-source tool. Flutter has the ability to easily test any application. The ability is that they work the way we want them on a target platform. Dart testing works well for unit and non-UI testing; It runs on the development machine and does not depend on the GUI of the Flutter application.

In this blog, we will explore Multi-select items In Flutter. We will also implement a demo of the Multi-select items In Flutter. How to use them in your flutter applications. So let’s get started.

multi_select_item | Flutter Package
Multi-select view item controller for GridView and ListView in Flutter For this to work. You need to write First define…pub.dev


Table Of Contents :

Multi-Select Item

Implementation

Code Implement

Code File

Conclusion


Multi-Select Item:

Multi-select Items This is a flutter library that handles multiple selections Using this library we create a list when we can delete the item of this list using this widget we wrap it inside the listview builder item So that we can easily create a multi-select list.

Implementation:

You need to implement it in your code respectively :

Step 1: Add dependencies.

Add dependencies to pubspec — yaml file.

First, we will add flutter_localization and intl library to pubspec. yaml.

dependencies:
multi_select_item: ^1.0.3

Step 2: import the package :

import 'package:multi_select_item/multi_select_item.dart';

Step 3: Enable AndriodX

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

Code Implementation:

For this to work. You need to write First define the controller first.

MultiSelectController controller = new MultiSelectController();

After this, we have created a list that defines its value inside initState() and after that set length of the controller by list length. the reference to the code below is included.

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

multiSelectList.add({"images": 'assets/images/resort_1.jpg', "desc":"Welcome to New York City!"});
multiSelectList.add({"images":'assets/images/resort_2.jpg' ,"desc":"Welcome to Los Angeles!"});
multiSelectList.add({"images":'assets/images/resort_3.jpg' ,"desc":"Welcome to Chicago!"});
multiSelectList.add({"images":'assets/images/resort_4.jpg', "desc":"Welcome to Houston!"});

controller.disableEditingWhenNoneSelected = true;
controller.set(multiSelectList.length);
}

Like after this we have taken a ListViewBuilder widget inside which we have taken MultiSelectItem() widget in which we have taken the card and in its child property, we have taken row widget in which we initialize above-defined list value which has an image and text and list on its onSelected() The controller is defined inside setState to select of the value.

ListView.builder(
itemCount: multiSelectList.length,
itemBuilder: (context, index) {
return MultiSelectItem(
isSelecting: controller.isSelecting,
onSelected: () {
setState(() {
controller.toggle(index);
});
},
child:Container(
height:75,
margin: EdgeInsets.only(left:15,right:15,top:15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.transparent,
),
child:Card(
color:controller.isSelected(index)
? Colors.grey.shade200:Colors.white,
shape: RoundedRectangleBorder(

borderRadius: BorderRadius.all(Radius.circular(8.0)),

),
child:Padding(
padding:EdgeInsets.symmetric(vertical:10, horizontal: 12),
child: Row(
children: [
//contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
ClipRRect(
borderRadius: BorderRadius.circular(12),
child:Image.asset(multiSelectList[index]['images'],fit:BoxFit.cover,width:60,height:60,),
),
SizedBox(width:20,),
Text(multiSelectList[index]['desc'], style: TextStyle(fontSize:14)),
],
),
),
),
),
);
},
),

After that we will remove the selected item to remove this we take forEach and sort the value in it which will sort our select item first from biggest id to smallest id and then it will remove it one by one.

void delete() {
var list = controller.selectedIndexes;
list.sort((b, a) =>
a.compareTo(b));
list.forEach((element) {
multiSelectList.removeAt(element);
});

setState(() {
controller.set(multiSelectList.length);
});
}

Code File :

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

class MultiSelectListDemo extends StatefulWidget {
@override
_MultiSelectListDemoState createState() => new _MultiSelectListDemoState();
}

class _MultiSelectListDemoState extends State<MultiSelectListDemo> {

List multiSelectList = [];

MultiSelectController controller = new MultiSelectController();

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

multiSelectList.add({"images": 'assets/images/resort_1.jpg', "desc":"Welcome to New York City!"});
multiSelectList.add({"images":'assets/images/resort_2.jpg' ,"desc":"Welcome to Los Angeles!"});
multiSelectList.add({"images":'assets/images/resort_3.jpg' ,"desc":"Welcome to Chicago!"});
multiSelectList.add({"images":'assets/images/resort_4.jpg', "desc":"Welcome to Houston!"});
multiSelectList.add({"images":'assets/images/sanfrancisco.jpg', "desc":"Welcome to San francisco!"});

controller.disableEditingWhenNoneSelected = true;
controller.set(multiSelectList.length);
}

void add() {
multiSelectList.add({"images": multiSelectList.length});
multiSelectList.add({"desc": multiSelectList.length});

setState(() {
controller.set(multiSelectList.length);
});
}

void delete() {
var list = controller.selectedIndexes;
list.sort((b, a) =>
a.compareTo(b));
list.forEach((element) {
multiSelectList.removeAt(element);
});

setState(() {
controller.set(multiSelectList.length);
});
}

void selectAll() {
setState(() {
controller.toggleAll();
});
}

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
var before = !controller.isSelecting;
setState(() {
controller.deselectAll();
});
return before;
},
child: new Scaffold(
appBar: new AppBar(
title: new Text('Selected ${controller.selectedIndexes.length}' ),
actions: (controller.isSelecting)
? <Widget>[
IconButton(
icon: Icon(Icons.select_all),
onPressed: selectAll,
),
IconButton(
icon: Icon(Icons.delete),
onPressed: delete,
)
]
: <Widget>[],
),
body:Container(

child: ListView.builder(
itemCount: multiSelectList.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {},
child: MultiSelectItem(
isSelecting: controller.isSelecting,
onSelected: () {
setState(() {
controller.toggle(index);
});
},
child:Container(
height:75,
margin: EdgeInsets.only(left:15,right:15,top:15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.transparent,
),
child:Card(
color:controller.isSelected(index)
? Colors.grey.shade200:Colors.white,
shape: RoundedRectangleBorder(

borderRadius: BorderRadius.all(Radius.circular(8.0)),

),
child:Padding(
padding:EdgeInsets.symmetric(vertical:10, horizontal: 12),
child: Row(
children: [
//contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
ClipRRect(
borderRadius: BorderRadius.circular(12),
child:Image.asset(multiSelectList[index]['images'],fit:BoxFit.cover,width:60,height:60,),
),
SizedBox(width:20,),
Text(multiSelectList[index]['desc'], style: TextStyle(fontSize:14)),
],
),
),
),
),
),
);
},
),
),
),
);
}
}

Conclusion :

In this article, I have explained Explore GetIt In Flutter, which you can modify and experiment with according to your own, this little introduction was from the Explore GetIt In Flutter demo from our side.

I hope this blog will provide you with sufficient information in Trying up the Explore GetIt In Flutter in your flutter project. We showed you what the Explore GetIt In Flutter is and work on it 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.


From Our Parent Company Aeologic

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

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

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

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

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

Future Completer In Dart

0

This blog will explore the Future Completer In Dart programming languageWe will perceive how to execute a demo program. Learn how to implement and use it in your applications. Which also works for the Flutter framework.

If you’re looking for the best Flutter app development company for your mobile application then feel free to contact us at — support@flutterdevs.com.


Table Of Contents::

Introduction

Completer

Complete Future

Complete Future with Error

Get Future and Value:

Get Completion Status

Conclusion



Introduction:

On the off chance that you’re utilizing Dart or developing a Flutter application, you may currently know about FutureFuture is typically used to deal with asynchronous tasks. Obtaining the consequence of a Future is very straightforward.

For instance, on the off chance that we have a capability Future fetchResult(), it’s feasible to obtain the outcome by utilizing the await keyword.

String result = await fetchResult();

Another alternative is to use a Future chain.

fetchResult()
.then((value) {
print(value);
});

However, in some cases, it’s impossible to use the methods above to create a Future. For example, if you need to get the result Future from a callback function. Let’s take a look at the example below. There is a class MyExectuor that has a method run. The class’s constructor has a required callback onDone. The run method will call the onDone method with a value. The objective here is to get the value passed to the onDone callback.

import 'dart:async';

class MyExecutor {

void Function(String time) onDone;

MyExecutor({
required this.onDone,
});

Future<void> run() async {
await Future.delayed(Duration(seconds: 2));
final DateTime time = DateTime.now();
final String formattedTime = '${time.year}-${time.month}-${time.day} ${time.hour}:${time.minute}:${time.second}';
onDone(formattedTime);
}
}

main() async {
final MyExecutor myExecutor = MyExecutor(
onDone: (String time) async {
// we want to get the value when this callback is invoked
}
);

await myExecutor.run();

}

Since the run technique returns void, and that implies it returns nothing, we can’t get the worth straight by utilizing await.run(). All things being equal, we need to get the worth inside the passed callback.

Completer:

In the first place, you want to make a Completer by calling its constructor. It has a type parameter where you can characterize the bring type back. The following is an illustration of a Completer that profits a string.final stringCompleter = Completer<String>();

On the off chance that it doesn’t have a return value, you can make a Completer with a void parameter type.

final voidCompleter = Completer<>();

In the event that you don’t determine the type parameter, it will be set as dynamic.

final dynamicCompleter = Completer(); // Completer<dynamic>

You can likewise utilize a nullable type in the event that the return value can be null.

final nullableStringCompleter = Completer<String?>();

Complete Future:

To finish the Future, you can call the complete technique with a return value. The value type should be equivalent to the type parameter while making the Completer. Assuming that the sort boundary is void, you don’t have to pass any value. On the off chance that it’s dynamic, you can return a value of any type. You are possibly permitted to return null assuming the sort parameter is void or nullable.void complete([FutureOr<T>? value]);

The following is an illustration of how to finish the Future with a string value.

stringCompleter.complete('foo');

The complete technique must be called once. On the off chance that What’s in store as of now is complete and you call the complete technique once more, it will throw StateError.

Complete Future with Error

A Future can likewise throw an error. With Completer, throwing an error should be possible by calling the completeError technique.

void completeError(Object error, [StackTrace? stackTrace]);

Here is an illustration of how to call the completeError technique

try {
// Do something
} catch (ex, stackTrace) {
stringCompleter.completeError(ex, stackTrace);
}

Get Future and Value:

Assuming you have a Completer case, you can get to the future property to get the Future that is finished when complete or completeError is called. Assuming you have the Future, you can utilize the await keyword to return the value by the Future.

 final valueFuture = stringCompleter.future;
final value = await valueFuture;

Get Completion Status:

To get the completion status Representing things to Future, you can get to the isCompleted property.

final isCompleted = stringCompleter.isCompleted;

Let’s put all the code together:

import 'dart:async';

class MyExecutor {
void Function(String time) onDone;

MyExecutor({
required this.onDone,
});

Future<void> run() async {
await Future.delayed(Duration(seconds: 2));
final DateTime time = DateTime.now();
final String formattedTime =
'${time.year}-${time.month}-${time.day} ${time.hour}:${time.minute}:${time.second}';
onDone(formattedTime);
}
}
main() async {
final stringCompleter = Completer<String>();

final MyExecutor myExecutor = MyExecutor(onDone: (String time) async {
try {
if (time.isNotEmpty) {
stringCompleter.complete(time);
} else {
throw Exception('empty time');
}
} catch (ex, stackTrace) {
stringCompleter.completeError(ex, stackTrace);
}
});

print('isCompleted: ${stringCompleter.isCompleted}');

await myExecutor.run();

print('isCompleted: ${stringCompleter.isCompleted}');
final valueFuture = stringCompleter.future;
final value = await valueFuture;
print('value: $value');
}

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

isCompleted: false
isCompleted: true
value: 2023-4-7 14:54:11

Process finished with exit code 0

Conclusion:

In the article, I have explained the Future Completer In Dart; you can modify this code according to your choice. This was a small introduction to the Future Completer In Dart User Interaction from my side, and it’s working using Flutter.

Completer can be utilized as a choice to make a Future in Dart/Flutter. The utilization is very basic. If you want to make a Completer, then call the complete or completeError strategy. You can get the Future of a Completer from the future property. The isCompleted property can be utilized to know whether What’s in Future has been finished.

I hope this blog will provide you with sufficient information on Trying the Future Completer In Dart of your projects. So please try it.

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

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

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

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

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

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.


Mouse Region Widget in Flutter

0

Sometimes we are required to perform a task or a set of operations that is with regard to the movement of the mouse. For instance take google maps as an example, where longitude and latitude change as per the movement of the mouse and shows you the landmark around the coordinates.

When interacting with a phone your input mechanism is pretty much limited. Have you ever tried to tap a single pixel but not the pixel around it ?? That might be impossible on a phone, but on other platforms (web) we have something else i.e. A mouse.

To know if a mouse is hovering within a particular area use the MouseRegion widget. Just take the widget that should be aware of the mouse movements and wrap it in a MouseRegion, then you will know if a mouse is within that region or not.


Table Of Contents::

Introduction

Constructor

Parameters

Implementation

Code File

Conclusion


Introduction :

MouseRegion is a widget that is used to track the movements of a mouse. MouseRegion is used when we have a specific portion on the device’s screen where we need interaction that can be noticed by the device in order to execute different callbacks e.g. onEnter, on hover, onExit.

This demo video shows how the device tracks the movement of the mouse and shows the current status of mouse movement status.

Constructor:

In order to use the Mouse Region widget, we just need to wrap out the widget inside the MouseRegion constructor.

There are constructor of MouseRegion class :

const MouseRegion({
Key? key,
this.onEnter,
this.onExit,
this.onHover,
this.cursor = MouseCursor.defer,
this.opaque = true,
this.child,
})

There are no required fields you need to pass to the constructor.

Parameters :

There are some parameters of MouseRegion :

  • child: The widget below this widget is in the tree.
  • cursor: The mouse cursor for mouse pointers that are hovering over the region.
  • onEnter: Triggered when a mouse pointer has exited this widget when the widget is still mounted.
  • onHover: Triggered when a pointer moves into a position within this widget without buttons pressed.
  • opaque: Whether this widget should prevent other MouseRegions visually behind it from detecting the pointer.

Implementation :

How to implement code in dart file :

This basic example will show you how to use the Mouse Region widget on any Flutter component.

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

Step 1: Create a class that extends StatefulWidget with a demo Container widget of some height and width in its body. Here we are assuming Container is a widget on which you need to track the movements of mice.

Container(
height: 80.0,
width: 80.0,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20.0),
border: Border.all(color: Colors.blueAccent),
),
)

Step 2: Simply wrap your Container around the MouseRegion class constructor as shown in the below code snippet.

MouseRegion(
child: Container(
height: 80.0,
width: 80.0,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20.0),
border: Border.all(color: Colors.blueAccent),
),
),
)

Step 3: According to your requirement change the mouse cursor using the cursor property.

cursor: SystemMouseCursors.click,

There are plenty of other options you can use to change cursors. Some of the basic cursors are :

SystemMouseCursors.click

SystemMouseCursors.help

SystemMouseCursors.move

SystemMouseCursors.allScrol l

SystemMouseCursors.cell

SystemMouseCursors.alias....

Step 4: According to your requirement trigger different events.

  • onEnter: This will trigger when a user enters the mouse in the region.
MouseRegion(
onEnter: (s) {
// your logic goes here...
},
)
  • onHover: This will trigger continuously long as the mouse is hovering on the region.
MouseRegion(
onHover: (s) {
// your logic goes here...
},
)
  • onExit: This will trigger when the mouse removes from the region.
MouseRegion(
onExit: (s) {
// your logic goes here...
},
)

Code File :

import 'package:flutter/material.dart';

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

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

class MyHomePage extends StatefulWidget {
String title;
MyHomePage({required this.title});

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

class _MyHomePageState extends State<MyHomePage> {
String status = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Mouse Status : $status'),
SizedBox(
height: 30,
),
MouseRegion(
cursor: SystemMouseCursors.click,
opaque: false,
onEnter: (s) {
setState(() {
status = 'Mouse Entered in region';
});
},
onHover: (s) {
setState(() {
status = 'Mouse hovering on region';
});
},
onExit: (s) {
setState(() {
status = 'Mouse exit from region';
});
},
child: Container(
height: 80.0,
width: 80.0,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20.0),
border: Border.all(color: Colors.blueAccent),
),
),
),
],
),
),
);
}
}

Conclusion :

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

I hope this blog will provide you with sufficient information on Trying up the MouseRegion widget in your flutter projects. This is recommended to try using this widget on different flutter widgets.

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


From Our Parent Company Aeologic

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

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

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

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

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


Keyboard Actions In Flutter

0

The Keyboard that Android/IoS offers does not bring the button to hide the keyboard so this causes lots of inconvenience to users. When our application has many TextFields that are required to display the action key on the toolbar and handle the functions which are defined to fields. Keyboard action is the key that indicates the action of the current field when the users tap into it.

In this post, I will demonstrate how to show keyboard actions in an application with the form input that contains the fields. We will also implement a demo program and use the package keyboard_actions to demonstrate the features. I have tried to explain my project in an easy way


Table Of Contents::

Introduction

Setting up Project

Code Implementation

Conclusion

GitHub Link


Introduction:

Flutter provides several packages to make your device keyboard customizable. Today, we are discussing KEYBOARD_ACTION. There is a long-known issue in iOS that it does not show the done button inside/above the keyboard in iOS when we use number input fields. So, Keyboard Action provides various features that are helpful to overcome issues that users and developer-facing nowadays.

Features:

  • Done button for the keyboard (You can customize the button).
  • Move up/down between your Textfields (You can hide for set nextFocus: false).
  • Keyboard Bar customization.
  • Custom footer widget below keyboard bar
  • Create your own Keyboard in an easy way
  • You can use it for Android, iOS, or both platforms.
  • Compatible with Dialog.

Setting up Project:

Step 1: Package Used

keyboard_actions | Flutter Package
Add features to the Android / iOS keyboard in a simple way. Because of the keyboard that Android / iOS offers us…pub.dev

Add youtube_player_iframe plugin in the dependencies in pubspec.yaml file. Then run $ flutter pub get command.

dependencies:
keyboard_actions: ^3.4.4

Step 2: Import the package as

import 'package:keyboard_actions/keyboard_actions.dart';

Code Implementation:

  1. Create a new dart file called home_screen.dart inside the lib folder to design the user interface and write the logic you want to implement in your project.
  2. I built long Forms in my flutter demo project and ran that app on Android. If we are on an IOS device then it does not show the done button inside/above the keyboard in iOS when we use number input fields and on Android, it does not show
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 8.0,
child: Container(
padding: EdgeInsets.only(left: 12),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Footer'),
controller: _customController,
focusNode: _nodeText6,
keyboardType: TextInputType.number,
),
TextFormField(
decoration: InputDecoration(labelText: 'Input Number'),
focusNode: _nodeText1,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next
),
TextFormField(
decoration: InputDecoration(
labelText: 'Custom cross Button'),
focusNode: _nodeText2,
keyboardType: TextInputType.text,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Action'),
focusNode: _nodeText3,
keyboardType: TextInputType.number,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Text without Done button'),
focusNode: _nodeText4,
keyboardType: TextInputType.text,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Toolbar Buttons'),
focusNode: _nodeText5,
keyboardType: TextInputType.number,
),
],
),
),
),
),
);

3. Now, to add Keyboard action in the project you need to wrap all TextFormField under the Widget KeyboardAction that required KeyboardActionsConfig config to add the configuration on your keyboard.

return KeyboardActions(
tapOutsideBehavior: TapOutsideBehavior.translucentDismiss,
//autoScroll: true,
config: _buildConfig(context),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 8.0,
child: Container(
padding: EdgeInsets.only(left: 12),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Footer'),
controller: _customController,
focusNode: _nodeText6,
keyboardType: TextInputType.number,
),

4. KeyboardAction provides a feature to dismiss the keyboard when we press anywhere outside the keyboard on your device screen. So, we need to add this line

tapOutsideBehavior: TapOutsideBehavior.translucentDismiss,

5. We should initialize the FocusNode object which is assigned to a different textformfield. So, developers do customization because it allows the keyboard focus to on this widget.

fnal FocusNode _nodeText1 = FocusNode();//Add In TextFormField TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Toolbar Buttons'),
focusNode: _nodeText1,
keyboardType: TextInputType.number,
)

6. We will define the KeyboardActionsConfig. Wrapper for a single configuration of the keyboard actions bar. Inside the KeyboardActionsConfig we define the actions which was performed by the keyboard independently for each TextFormField on basis of your requirement. We can customize the keyboard color, Color of the line separator between keyboard and content, display arrows prev/next to move focus between inputs.

KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.ALL,
keyboardBarColor: Colors.grey[200],
keyboardSeparatorColor: Colors.redAccent,
nextFocus: true,
actions: [

7. Now, we will define action according to our requirements in different TextFormField.

actions: [
KeyboardActionsItem(
focusNode: _nodeText1,
),

8. To show input with a custom footer in your application you need to implement the below code in your KeyboardActionsItem where we have to pass the TextController in the Text widget.

KeyboardActionsItem(
focusNode: _nodeText6,
footerBuilder: (_) => PreferredSize(
child: SizedBox(
height: 40,
child: Center(
child: Text(_customController.text),
)),
preferredSize: Size.fromHeight(40)),
),

9. To display the show custom dialogue in your app add this logic inside the KeyboardActionsItem to the specified focus node.

KeyboardActionsItem(
focusNode: _nodeText3,
onTapAction: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text("Show Custom Action"),
actions: <Widget>[
FlatButton(
child: Text("OK"),
onPressed: () => Navigator.of(context).pop(),
)
],
);
});
},
),

When we run the application, we get the screen’s output video like this where user can observe the output.

Conclusion:

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Keyboard_Action:

GitHub – flutter-devs/KeyboardAction: Add customization in keyboard
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…github.com


From Our Parent Company Aeologic

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

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

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

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

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


Explore Motion Bottom TabBar In Flutter

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

In this article, we will explore the Explore Motion Bottom TabBar In Flutter using the motion_tab_bar_package. With the help of the package, Users can use this to give the bottom bar an animation type of tab bar motion on click of item. So let’s get started.

motion_tab_bar | Flutter Package
A beautiful animated widget for your Flutter apps |———|———-| | | Add the plugin: dependencies…pub.dev


Table Of Contents :

Motion Bottom TabBar

Implementation

Code Implement

Code File

Conclusion


Motion Bottom TabBar :

The Motion Tab Bar Plugin in Flutter provides us with a motion animation, this is a kind of bottom tab bar, when we tap on the item in the tab bar, we see that it animates to the next item in the upward motion flow. It can be used instead of the bottom tab bar, it is very good and an attractive bottom tab bar.

Implementation :

Step 1: Add the dependencies

Add dependencies to pubspec — yaml file.

dependencies :

dependencies:
motion_tab_bar: ^0.1.5

Step 2: Importing

import 'package:motion_tab_bar/MotionTabBarView.dart';
import 'package:motion_tab_bar/MotionTabController.dart';
import 'package:motion_tab_bar/TabItem.dart';
import 'package:motion_tab_bar/motiontabbar.dart';

Step 3: Enable AndriodX

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

Code Implementation :

You need to implement it in your code respectively:

Before exploring the motion tab bar we will create a controller and define it inside initState() and define it inside the initialIndex property in MotionTabController().

late MotionTabController _tabController;

@override
void initState() {
super.initState();
_tabController = MotionTabController(initialIndex: 1, vsync: this);
}

We will add MotionTabBar() in bottomNavigationBar. Inside, we will add labels, initialSelectedTab, tabIconColor and onTabItemSelected. In onTabItemSelected, we will add inside setState() method. In this method, we will add _tabController.index is equal to the value. Also, add icons and textStyle.bottomNavigationBar:

MotionTabBar(
labels: [
"Account","Home","Dashboard"
],
initialSelectedTab: "Home",
tabIconColor: Colors.green,
tabSelectedColor: Colors.red,
onTabItemSelected: (int value){
print(value);
setState(() {
_tabController.index = value;
});
},
icons: [
Icons.account_box,Icons.home,Icons.menu
],
textStyle: TextStyle(color: Colors.red),
),

After this we will use MotionTabBarView in the motion tab bar, inside it we have taken three different types of container which has some different type of text on its child when we tap on a given item of bottom navigation bar then a different type of page according to index will show.

MotionTabBarView(
controller: _tabController,
children: <Widget>[
Container(
child: Center(
child: Text("Account"),
),
),
Container(
child: Center(
child: Text("Home"),
),
),
Container(
child: Center(
child: Text("Dashboard"),
),
),
],
)

Code File :

import 'package:flutter/material.dart';
import 'package:motion_tab_bar/MotionTabBarView.dart';
import 'package:motion_tab_bar/MotionTabController.dart';
import 'package:motion_tab_bar/motiontabbar.dart';

class MotionTabBarDemo extends StatefulWidget {
@override
_MotionTabBarDemoState createState() => _MotionTabBarDemoState();
}

class _MotionTabBarDemoState extends State<MotionTabBarDemo>with TickerProviderStateMixin {
late MotionTabController _tabController;

@override
void initState() {
super.initState();
_tabController = MotionTabController(initialIndex: 1, vsync: this);
}

@override
void dispose() {
super.dispose();
_tabController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Motion Tabbar Demo'),
),
bottomNavigationBar: MotionTabBar(
labels: [
"Account","Home","Dashboard"
],
initialSelectedTab: "Home",
tabIconColor: Colors.green,
tabSelectedColor: Colors.red,
onTabItemSelected: (int value){
print(value);
setState(() {
_tabController.index = value;
});
},
icons: [
Icons.account_box,Icons.home,Icons.menu
],
textStyle: TextStyle(color: Colors.red),
),
body: MotionTabBarView(
controller: _tabController,
children: <Widget>[
Container(
child: Center(
child: Text("Account"),
),
),
Container(
child: Center(
child: Text("Home"),
),
),
Container(
child: Center(
child: Text("Dashboard"),
),
),
],
)
);
}
}

Conclusion:

In this article, I have explained Glassmorphism Card In Flutter, which you can modify and experiment with according to your own, this little introduction was from the Glassmorphism Card In Flutter demo from our side.

I hope this blog will provide you with sufficient information on Trying up the Glassmorphism Card In Flutter in your flutter project. We showed you what the Glassmorphism Card In Flutter is and work on it 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.


From Our Parent Company Aeologic

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

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

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

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

HeroMode Widget in Flutter

0

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

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


Table Contents:

Flutter

Hero Widget

HeroMode Widget

Code Implementation

Conclusion

GitHub Link


Flutter :

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

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

If you want to explore more about Flutter, please visit Flutter’s official website to get more information.

Flutter Is Proudly Entrusted By These Organizations For their Products : — Flutter Showcase


Hero Widget:

Hero widget is a great out-of-the-box animation for communicating the navigation action of a widget flying from page to page. Hero animation is a shared element transition (animation) between two different pages. Now to See this, Imagine a superhero flying in action. For example, you must have an image list. As we wrap it with a hero tag. Now we tap on an item list. and when tapped. Then the images list item lands its position on the detail page. when we cancel it and come back to the list page, then the hero widget returns to its page.

HeroMode Widget:

HeroMode widget has animation power to enable or disable the element between two screens. basically, this widget is required, when you want to disable the animation functionality of the Hero widget. If you want to know about the Hero Mode widget, then first you need to understand the Hero widget.

HeroMode widget is the part of the Hero widget, and the purpose of introducing this widget is to enable and disable the animation of the hero widgets, if you don’t want to animate the element between two screens then wrap the Hero widget with the HeroMode Widget and we can enable and disable by using their static properties or dynamically, and then by wrapping this widget what happened when you see carefully below example video, then you can see what is the measurable difference in this animation.

Demo Module :

How to implement code in dart file :

You need to implement it in your code respectively:

First, I have created a ViewModel class for the set and get a boolean value on the switch button. Which I passed in HeroMode Widget.

bool _isHeroModeEnable= true;

bool get isHeroModeEnable => _isHeroModeEnable;set isHeroModeEnable(bool value) {
_isHeroModeEnable = value;
}

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

Then, I have to add a text and switch button for showing enable and disable the functionality of the HeroMode widget.

Widget buildCategoriesSection() {
return Container(
padding: EdgeInsets.only(left: 20),
child: Row(
//mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Text("Hero Mode",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold
),),
),
Switch(
value: model!=null && model!.isHeroModeEnable,
onChanged:(value){
print("value:$value");
model!.isHeroModeEnable=value;
},
activeTrackColor: Color(ColorConstants.light_blue),
activeColor: Color(ColorConstants.pure_white),
),

],
),
);
}

Then, I have created a listview with movie banner API, but you can use a dummy images list for test purposes according to your requirement. and after that, I have wrap images with the Hero widget, and Hero widget wrap with the HeroMode widget. for disabling the animation of Hero Widget. basically, this is a medium to enable and disable the animation of Hero Widget .you can not disable animation directly from the Hero Widget.

Widget _buildPopularSection() {
return Container(
height: 300,
padding: EdgeInsets.only(left: 20, top: 5),
width: MediaQuery.of(context).size.width,
child: model != null && model!.isPopularLoading
? Center(child: CircularProgressIndicator())
: Provider.value(
value: Provider.of<HomeViewModel>(context),
child: Consumer(
builder: (context, value, child) => Container(
child: ListView.builder(
shrinkWrap: true,
itemCount: model != null && model!.popularMovies != null
? model!.popularMovies!.results!.length : 0,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return _buildPopularItem(
index, model!.popularMovies!.results![index]);
},
),
),
),
),
);
}Widget _buildPopularItem(int index, Results result) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MovieDetailView(movieDataModel: result)),
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 200,
width: 150,
margin: EdgeInsets.only(right: 16),
child: HeroMode(
child: Hero(
tag: '${result.id}',
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: Image.network(
Constants.IMAGE_BASE_URL +
Constants.IMAGE_SIZE_1 +
'${result.posterPath}',
fit: BoxFit.cover,
),
),
),
enabled: true,
//enabled:model.isHeroModeEnabled,
),
),
SizedBox(
height: 18,
),
Container(
child: Text(
result.title!,
style: TextStyle(color: Colors.white, fontSize: 15),
),
),
SizedBox(
height: 5,
),
Container(
child: GFRating(
value: _rating,
color: Color(ColorConstants.orange),
size: 16,
onChanged: (value) {
setState(() {
_rating = value;
});
},
),
)
],
),
);
}

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

Last, I have created a second dart file and in this file, I have made a method for showing images animation here. and then images wrap with the Hero widget with the same tag. When you have multiple images then you pass the image list id.

Widget _buildMovieBanner(Results movieItems) {
return Container(
height: 380,
child: Stack(
children: [
Positioned(
top: 20,
child: Container(
height: 350,
width: 240,
margin: EdgeInsets.only(left: 28, right: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
color: Color(ColorConstants.saphire_blue2),
),
),
),
Positioned(
top: 10,
child: Container(
height: 350,
width: 250,
margin: EdgeInsets.only(left: 22, right: 25),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
color: Color(ColorConstants.cobaltBlue),
),
),
),
Container(
height: 350,
width: 260,
margin: EdgeInsets.only(left: 16, right: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(24),
child: Hero(
tag: '${widget.movieDataModel.id}',
child: Image.network(
Constants.IMAGE_BASE_URL +
Constants.IMAGE_SIZE_1 +
widget.movieDataModel.posterPath!,
fit: BoxFit.cover,
),
),
),
),
],
),
);
}

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Flutter HeroMode Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


SnackBar Widget in Flutter

0

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

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


Table Contents:

SnackBar Widget

Code Implementation

Code File

Conclusion

GitHub Link



SnackBar:

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

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

Demo Module :


How to implement code in dart file :

You need to implement it in your code respectively:

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

Default SnackBar

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

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

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

another_flushbar: ^1.10.24

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

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

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

});
}

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

Custom SnackBar

Code File:

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

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

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

class _SnackBarViewState extends State<SnackBarView> {

@override
Widget build(BuildContext context) {

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

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

),),
),

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

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

),),
),

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

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

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

});
}

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

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Flutter SnackBar Demo:

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


From Our Parent Company Aeologic

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

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

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

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

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


Slide Transition Widget In Flutter

0

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

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


Table Contents:

Slide Transition

Constructor

Properties

PageRoughtBuilder

Code Implementation

Conclusion

GitHub Link


Slide Transition:

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

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

Demo Module :


Constructor:

Default Constructor for it will look like as below:

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

Properties:

There are some properties of Slide Transition are:

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

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

PageRouteBuilder:

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

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

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

How to implement code in the dart file:

You need to implement it in your code respectively:

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

pubspec. yaml:

custom_radio_grouped_button: any

Then add custom radio buttons.

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

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

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

Now implement SlideTransition Widget.

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

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

AnimationController _controller;
Animation<Offset> _animation;

initState() will have a code sample as below:

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

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

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

First left to right animation implementations code sample are:

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

The second right to left animation implementations code sample is:

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

The third top to bottom animation implementations code sample is:

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

The fourth bottom to top animation implementations code sample is:

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

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

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

The six side animation implementations code sample.

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the Slide Transition:

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


From Our Parent Company Aeologic

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

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

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

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

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


RefreshIndicator In Flutter

0

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


Table Contents:

RefreshIndicator Widget

Code Implementation

Conclusion

GitHub Link


RefreshIndicator:

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

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

Demo Module :


Code Implementation:

How to implement code in the dart file:

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

We will deeply define below the code.

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

We will define buildCardView() method:

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

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

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

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

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

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

Conclusion:

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

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

❤ ❤ Thanks for reading this article ❤❤

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

Clap 👏 If this article helps you.


GitHub Link:

find the source code of the RefreshIndicator Demo:

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


From Our Parent Company Aeologic

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

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

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

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