Hi Guy’s Welcome to Proto Coders Point. This NodeJS article is on solving a commonly faced error while working with nodejs application “listen EADDRINUSE: Address already in use – NodeJS”.
The Error we get
When working with nodejs + Express.js that works on particular port number, and you see an error “Address already in use”
Error: listen EADDRINUSE: address already in use :::3000
This simply means that port number 3000 is already in used by some other program or application, and thus can’t us the same port.
Here is the full error message that you get:
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1380:16)
at listenInCluster (node:net:1428:12)
at Server.listen (node:net:1516:7)
at Function.listen (/Users/goodman/Desktop/Projects/kindacode/api/node_modules/express/lib/application.js:635:24)
at server (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:60:7)
at bootstrap (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:73:3)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'EADDRINUSE',
errno: -48,
syscall: 'listen',
address: '::',
port: 3000
}
As I said port 3000 is been used by some other program.
Solution for : EADDRINUSE: address already in use
Solution 1 : Change port number of current nodejs express server application
In current nodejs application that you are trying to run you can simply change the port address from 3000 to someother port (3001), thus your application will run prefectly.
Solution 2 : npx kill port
You need to stop the program that is been running on port number 3000.
Sometimes you will not be able to find the program that is running on port 3000, This happens when the nodejs crashes in background but is till utilizing the port.
You need to simply kill the port that is running
Execute the below command:
npx kill-port 3000
Here if you want to free up unused port (multiple port) that are running then use the command as below
npx kill-port 3001 3002 5010 6100 8080
If non of the above works for you, then solution 3 will definitely work
Solution 3: Simple restart your computer
Just restart your pc/laptop and the used address port will automatically get killed or free.
Hi Guy’s, Welcome to Proto Coders Point. In this flutter tutorial let’s create a Sidebar Navigation Menu using a package i.e. Flutter SidebarX.
Flutter SidebarX
Let’s get started
In flutter there are two ways to create a navigation i.e. by tabs & Drawer. I found out a flutter package that is recently launched SideBarX using which flutter app developer can easily create multiplatform navigation drawer sidebar/ sidebar menu / side navigation drawer.
Sidebar Navigation menu is very useful for user for in-app navigation(page routing) or for user profile.
In this flutter tutorial Article let’s create a simple sidebar navigation menu by using flutter sidebarX package.
1. Create a new Flutter project or open any existing to implement sidebarX
I use Android Studio to build flutter application, you can use your favorite IDE.
create Project -> Android Studio -> File -> New -> New Flutter Project -> Give Project Name -> create project by click Finish.
2. Add/Install SidebarX package as dependencies
In your project structure look for file by name pubspec.yaml, Open it & under dependencies section add sidebarx package, as shown in below screenshot.
click on pub get to download the package as external libraries.
3. Import SidebarX
Once the sidebarx dependencies is added into you flutter project as external libraries, To use it you need to import it.
import 'package:sidebarx/sidebarx.dart';
4. SidebarX Widget Properties
properties
usage
controller :
controller are used to give controller parent widget to listen to any event or chile state
theme : SidebarXTheme()
Give a Theme to your sidebar navigator
extendedTheme:
Can be used to increase the sidebar size usign SidebarX theme
footerDivider:
Gives a Divider at the footer Diviter
headerBuilder
Set a header at the top of sidebar, can be used to show profile image
items:[]
List of SidebarXItem using which user can navigate between pages
Hi Guys, Welcome to Proto Coders Point. This Article is on How to Validate email TextField in flutter.
We will use RegExp to validate email textfield, This will be a real time email validation form as user is typing in the form we will check the validation for every string the user enter.
Hi Guys, Welcome to Proto Coders Point. In flutter project structure IOS info.plist file path location is:-
<Project>/ios/Runner/Info.plist
flutter project do not contain IOS folder (flutter IOS folder missing). You might have forgot to tick IOS while creating new flutter project in android studio/VSCode.
No Issue, you can create IOS folder in existing flutter project by running below command by being into Root Folder of project:-
flutter create -i swift
What is Info.plist file used for
In flutter IOS Info.plist file is useful to provide application metadata to the system. plist files syntax is in XML format. IOS & Flutter developer mostly use Info.plist file when they need special permission to implement certain feature in app (like accessing camera, microphone, accessing gallery, use for Bluetooth)
And your task is to sort this map in a form of ascending/descending order as per the project requirement.
The solution to sort map values in ascending or descending order is quite easily & simple then you thing it is.
Flutter Dart Sort map in ascending order by its values
Video Tutorial
void main() {
final Map<String,int> mapData = {
'a' : 100,
'b' : 90,
'c' : 50,
'd' : 150,
'e' : 200,
'f' : 600,
};
// sorting the map value in ascending order by it's value.
// convert the map data into list(array).
List<MapEntry<String,int>> listMappedEntries = mapData.entries.toList();
// Now will sort the list
listMappedEntries.sort((a,b)=> a.value.compareTo(b.value));
// list is been sorted
// now convert the list back to map after sorting.
final Map<String,int> sortedMapData = Map.fromEntries(listMappedEntries);
print(sortedMapData);
}
Output
Flutter Dart Sort map in descending order by its values
The code is similar to above example, The only thing is while sorting compering, We must compare reverse i.e.
void main() {
final Map<String,int> mapData = {
'a' : 100,
'b' : 90,
'c' : 50,
'd' : 150,
'e' : 200,
'f' : 600,
};
// sorting the map value in ascending order by it's value.
// convert the map data into list(array).
List<MapEntry<String,int>> listMappedEntries = mapData.entries.toList();
// Now will sort the list in descending order
listMappedEntries.sort((a,b)=> b.value.compareTo(a.value));
// list is been sorted
// now convert the list back to map after sorting.
final Map<String,int> sortedMapData = Map.fromEntries(listMappedEntries);
print(sortedMapData);
}
Output
Flutter map sort by key example
All you need to do is use inbuilt sort function and compare map key with key, and thus map will get sorted by key.
void main() {
final Map<String,int> mapData = {
'a' : 100,
'z' : 90,
'f' : 50,
'b' : 150,
'n' : 200,
'r' : 600,
};
// sorting the map value in ascending order by it's value.
// convert the map data into list(array).
List<MapEntry<String,int>> listMappedEntries = mapData.entries.toList();
// dart map sort by key
listMappedEntries.sort((a,b)=> a.key.compareTo(b.key));
// list is been sorted
// now convert the list back to map after sorting.
final Map<String,int> sortedMapData = Map.fromEntries(listMappedEntries);
print(sortedMapData);
}
Hi Guys, Welcome to Proto Coders Point. In this Flutter article let’s learn how to show popup menu item on long press on a widget.
There might be a requirement in flutter app development. i.e. when a user long press on a widget we should show a context menu item, & the position of flutter popup menu should be near by the long tapped location of the screen.
GestureDetector(
onTapDown: (position)=>{
_getTapPosition(position) /* get screen tap position */
},onLongPress: ()=>{
_showContextMenu(context) /* action on long press
},
child: Image.network('https://images.pexels.com/photos/674010/pexels-photo-674010.jpeg?cs=srgb&dl=pexels-anjana-c-674010.jpg&fm=jpg',width: 300,height: 300,)
)
Function – Flutter Get Tap position X & Y Coordinates
The below function will help us in getting user tap position i.e. X & Y coordinate of our mobile screen.
Snippet Code:
void _getTapPosition(TapDownDetails tapPosition){
final RenderBox referenceBox = context.findRenderObject() as RenderBox;
setState(() {
_tapPosition = referenceBox.globalToLocal(tapPosition.globalPosition); // store the tap positon in offset variable
print(_tapPosition);
});
}
Flutter popup menu on long press at tap position
The below function will show a popup context menu item at long press position on the screen.
In out function, will use a in-built function i.e. showMenu that will help use in showing context menu items.
In showMenu function, we need to pass 3 parameter:
context:
position: /* position where user have long pressed to load popup menu items. /*
items: /* list of popupmenuItem */
Menu function snippet code
Snippet Code:
void _showContextMenu(BuildContext context) async {
final RenderObject? overlay =
Overlay.of(context)?.context.findRenderObject();
final result = await showMenu(
context: context,
position: RelativeRect.fromRect(
Rect.fromLTWH(_tapPosition.dx, _tapPosition.dy, 100, 100),
Rect.fromLTWH(0, 0, overlay!.paintBounds.size.width,
overlay!.paintBounds.size.height)),
items: [
const PopupMenuItem(
child: Text('Add Me'),
value: "fav",
),
const PopupMenuItem(
child: Text('Close'),
value: "close",
)
]);
// perform action on selected menu item
switch (result) {
case 'fav':
print("fav");
break;
case 'close':
print('close');
Navigator.pop(context);
break;
}
}
Flutter show popup context menu near long press position
Will keep it simple. Will have a Image Widget at the center of screen, The Image Widget is been wrapped with GestureDetector therefore, When user long press on image widget we get the tap position using onTapDown() & onLongPress() will popup a context menu items which 2 options (Add to favorite & a Close menu).