DevDocs provides a collection documentation of all the programming into one that can we easily searchable. You can access documentation pertaining to a multitude of programming languages and technologies in a centralized location.
css are used in web development, so if you want to get strong in website designing using CSS then css-tricks.com is the place where you can master web application development.
OverAPI provides you a cheat sheets for majority of programming tips and tricks, This website is best for all software developers who want to to quickly find a solution and implement it in projects.
If you are a programming content creator, you might be sharing your code on social media with your audience, By using ray.so website can can create a beautiful screenshots of your codes and share the image on your social media account.
This is a Website and share daily developer feeds, Here you get daily news articles related to technology. The tag line is Where Developers grow together, Using this you can make learning a daily habit.
This website provides roadmaps, guidelines, and other educational content to assist developers in choosing a path and directing their learning. It is very helpful for a beginner as well as a learner who needs guidance.
Flutter To-Do App
With
Nodejs + mongodb
at Backend
Hi Guy’s, In this Flutter Tutorial, We will build a Flutter Todo App with NodeJS & MongoDB at backend. In this article I have covered Fully Functional App with CRUD (Create, Read, Update, Delete) Operation in Flutter Todo Application, The User will be Authenticated using JSON Web Tokens & With JWT Tokens Flutter app used will be kept online.
We will cover everything from setting up Restful API with NODEJS, Integrating Mongodb for database management and creating the Flutter todo app with user authentication.
Complete Video Tutorial on Flutter Todo App with NodeJS & MongoDB at Backend
NodeJS Backend
NodeJS Todo App Setup
npm packages used:
bcrypt
body-parser
express
jsonwebtoken
mongoose
nodemon
NodeJS Project Structure for ToDo app
NodeJS Project Structure for ToDo app
Note: How our code execute? The Code Follow
index.js -> app.js -> router -> controller -> service
index.js
const app = require("./app");
const db = require('./config/db')
const port = 3000;
app.listen(port,()=>{
console.log(`Server Listening on Port http://localhost:${port}`);
})
In this file, we have setup our mongodb database connection. This file is been imported in models so whenever model is been used to perform CRUD operation db will get connected automatically and CRUD operation is been performed.
model is nothing but a database model, Here I have made use of mongoose to create a db schema for user collection and todo list collection as below.
user.model.js
In user schema, we are storing user email & password. Note that here password will be get encrypted using bcrypt package before the data gets stored in user db collection.
const db = require('../config/db');
const bcrypt = require("bcrypt");
const mongoose = require('mongoose');
const { Schema } = mongoose;
const userSchema = new Schema({
email: {
type: String,
lowercase: true,
required: [true, "userName can't be empty"],
// @ts-ignore
match: [
/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,
"userName format is not correct",
],
unique: true,
},
password: {
type: String,
required: [true, "password is required"],
},
},{timestamps:true});
// used while encrypting user entered password
userSchema.pre("save",async function(){
var user = this;
if(!user.isModified("password")){
return
}
try{
const salt = await bcrypt.genSalt(10);
const hash = await bcrypt.hash(user.password,salt);
user.password = hash;
}catch(err){
throw err;
}
});
//used while signIn decrypt
userSchema.methods.comparePassword = async function (candidatePassword) {
try {
console.log('----------------no password',this.password);
// @ts-ignore
const isMatch = await bcrypt.compare(candidatePassword, this.password);
return isMatch;
} catch (error) {
throw error;
}
};
const UserModel = db.model('user',userSchema);
module.exports = UserModel;
todo.model.js
In todo collection, we store userId, title, description. Here userId is stored just to know this data belong to which user, so that we can use userId to fetch data only of that particular user.
In user router, we will handle user registration & login event through which user will be able to create his account into mongodb database using /register api and then get signIn using /login api
In todo routes, we will handle user event from flutter application like user will be able to add his todo data, get all the todo list of a particular signed In user and delete his todo list.
In controllers, We have function that handle request & response. Here in request we get parameters requested from frontend i.e. flutter app and response the data from backend to frontend for the requested data to the app.
user.controller.js
In user.controller.js we have 2 functions (register & login).
The register function is used to create account of a user.
The login function helps used to get login into the application.
const UserServices = require('../services/user.service');
exports.register = async (req, res, next) => {
try {
console.log("---req body---", req.body);
const { email, password } = req.body;
const duplicate = await UserServices.getUserByEmail(email);
if (duplicate) {
throw new Error(`UserName ${email}, Already Registered`)
}
const response = await UserServices.registerUser(email, password);
res.json({ status: true, success: 'User registered successfully' });
} catch (err) {
console.log("---> err -->", err);
next(err);
}
}
exports.login = async (req, res, next) => {
try {
const { email, password } = req.body;
if (!email || !password) {
throw new Error('Parameter are not correct');
}
let user = await UserServices.checkUser(email);
if (!user) {
throw new Error('User does not exist');
}
const isPasswordCorrect = await user.comparePassword(password);
if (isPasswordCorrect === false) {
throw new Error(`Username or Password does not match`);
}
// Creating Token
let tokenData;
tokenData = { _id: user._id, email: user.email };
const token = await UserServices.generateAccessToken(tokenData,"secret","1h")
res.status(200).json({ status: true, success: "sendData", token: token });
} catch (error) {
console.log(error, 'err---->');
next(error);
}
}
todo.controller.js
In todo controller, We have 3 function that perform different task (createToDo, getTodoList, deleteToDo).
Here I have create a common page to show a app logo wherever required.
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
class CommonLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.network("https://pluspng.com/img-png/avengers-logo-png-avengers-logo-png-1376.png",width: 100,),
"To-Do App".text.xl2.italic.make(),
"Make A List of your task".text.light.white.wider.lg.make(),
],
);
}
}
config.dart
In config file, I have Listed all the url that point to nodejs backend API.
final url = 'http://192.168.29.239:3000/';
final registration = url + "registration";
final login = url + 'login';
final addtodo = url + 'storeTodo';
final getToDoList = url + 'getUserTodoList';
final deleteTodo = url + 'deleteTodo';
main.dart
From main page, user will get navigated to respective page depending on the state of an app. Here If user has login into the app I have stored the user login details inside a token variable which is been stored in sharedPreferences. The Token is been generated by our backend using JWT token which contain expire time.
So here if token don’t exist then it means that the user is new and yet to login so we simply navigate the user to login page.
If Token Exist, It will have a Expire time we make use of JWT decoder to decode the token and check if it is expired or not, then if the token is expired then navigate the user to login page else if token is not expired and still valid then navigate the user to dashboad page.
In registration page, user will be able to create his account into flutter todo app and register himself. Here he has to fill his email & password to create his account.
Once the user create his account then he can make use of his email & password to login into the todo flutter application. If the login detail entered by user is correct then the user get navigated to dashboard page.
Once the user successfully get login into flutter todo list app, From the dashboard page he will be able to perform 3 task i.e. add todo, delete todo item, and get all the todo data.
add todo list: To add Todo list use has to click on floating action button that popup a dialog box, In dialog box we have 2 Text Field to Enter title & description of todo item.
flutter todo add item
dashboard todo List: In dashboard we will show all the todo list created by user in a ListView.
Flutter show list of todo list item in listview
delete todo item: To delete item from the todo listview, user has to select the listview listtile and slide to see an option to delete the item.
In Flutter App development where we use dart language, we can replace or remove substrings from the original string using dart In-Built String Methods:
replaceAll()
replaceAllMapped()
replaceFirst()
replaceFirstMapped()
replaceRange()
Now, let’s use each of this dart string method to replace string.
Dart replaceAll() method
In below Example, We are use replaceAll() function, so what this will do is it will replace all the occurences of word/substring “easy” with “difficult” in the given string.
In below Example, I want to replace range of index from the given string. From example I have a String sentence “The bird is sitting on the branch, The bird is Looking Beautiful”. here I want to replace “bird” with “sparrow” by using range/index of string.
the replaceRange() method accepts 3 parameter replaceRange(startIndex , EndIndex, replacement string) as shown below:
void main() {
String str = "The bird is sitting on the branch, The bird is Looking Beautiful";
String newStr = str.replaceRange(4, 8, "sparrow");
print(newStr);
}
Output of above dart code
The sparrow is sitting on the branch, The bird is Looking Beautiful
Dart replaceAllMapped() method
Suppose I want to replace all the words that has 8 letters in the given string, then at this time I can make use of replaceAllMapped() function.
void main() {
String str =
"I Like to play fortnite game and Learn Programming from Proto Coders Point";
// Here I am using Regular Expression to match 8 letter word in given string
// and then replace it with _________
var pattern = RegExp(r'\b\w{8}\b');
String replacement = "________";
String newStr = str.replaceAllMapped(pattern, (match) => replacement);
print(newStr);
}
In Above code I am using Regular Expression to match 8 letter word in given string and then replace it with _____.
Output of above dart code
I Like to play ________ game and Learn Programming from Proto Coders Point
Dart replaceFirst() Method
Suppose you want to replace only the first word that occurs in the given string, Let’s say I have sentence “don’t have a bad day have a great day, because bad day will come and go”. Here I want to only change first occurrence of word bad, In such situation I can make use of dart replaceFirst() methon.
void main() {
String str =
"don't have a bad day have a great day";
String substr = "bad";
String replacement = "good";
String newStr = str.replaceFirst(substr, replacement);
print(newStr);
}
Output of above dart code
don't have a good day have a great day
Dart replaceFirstMapped() method
In below example, I have a sentence “I Like to play fortnite game, fortnite is my favourite game and Learn Programming from Proto Coders Point”, which contain 8 letter word “fortnite” for 2 times, I want to replace only the first occurrences of it.
void main() {
String str =
"I Like to play fortnite game, fortnite is my favourite game and Learn Programming from Proto Coders Point";
// Here I am using Regular Expression to match 8 letter word in given string
// and then replace it with _________
var pattern = RegExp(r'\b\w{8}\b');
String replacement = "________";
String newStr = str.replaceFirstMapped(pattern, (match) => replacement);
print(newStr);
}
Output of above dart code
I Like to play ________ game, fortnite is my favourite game and Learn Programming from Proto Coders Point
To remove any word from a given string then simple pass an empty replacement (“”)
str.replaceAll("bad",""); // by doing this bad word from a given string will get removed.
In this article, we’ll integrate Twitter login and Firebase authentication into our Flutter application. This will allow us to retrieve user information from the home page after a user has been authenticated by logging in with their Twitter account.
Any application can benefit from user authentication. Once an app recognises each unique user using the app. The content of your app can then be altered so that it appears to have been created with a particular user in mind.
One of the options for user authentication in applications is Twitter. Users of the application can log in using the Twitter APIs. By simply using their Twitter account to log in, users can avoid filling out a lengthy registration form. It is much quicker and simpler to get users signed into your app using an account they’ve already created with an external authentication provider, like Facebook or Twitter, with the aid of social networks.
We’re going to integrate Twitter into our Flutter application in this post.
You will discover how to Create a New Application on Twitter Developer Console here.
The user can log in to get their name and authentication.
Firebase project setup
1). Log in to the Firebase console, then click Add project.
Open the firebase console and tap the “Add project option” , and get this type of screen.
Here add your firebase project name.
2). Select your existing Google Cloud project from the dropdown menu, then click Continue.
3). (Optional) Enable Google Analytics for your project, then follow the prompts to select or create a Google Analytics account.
The firebase console might take some few seconds to go through your application. Once that is completed, then click the continue option to open the overview page of the project you made.
Android app set up with firebase console
For android app set up 👍
1). To create an android app in the Firebase console for twitter sign-in flutter, select the option android from this list.
2). Fill up this whole information and register your application on firebase console
App registration and console progress.
i) Install the necessary command-line tools as the first step. Get the Firebase CLI installed if you haven’t already.
ii) Configure your apps to use Firebase in step two. To set up a connection between your Flutter apps and Firebase, use the Flutter Fire CLI.
iii) Initialize Firebase in your application.
iv) Add Firebase plugins in the app.
Authentication
1). Click on the Authentication.
2). Click Get started with the sign-in method and select twitter.
Presently enable twitter , and you need to enter the project apikey and api secrate. Empower this by tapping the switch on the upper right corner. At that point, click Save.
To obtain a consumer key and a consumer secret, register the Twitter app.
You need a Twitter consumer key and consumer secret, which are used to make Twitter API calls, in order to implement the Twitter login feature in a Flutter application. Therefore, you can get the keys by registering a new Twitter application and following the steps below:
1). Register a new application on the Twitter developer page.
The Twitter sign-in is enabled and authenticated. You will be prompted for the API secret and key.
This method causes the user to be signed out by the signOut method.
Create FirebaseAuth instance
FirebaseAuth _auth = FirebaseAuth.instance;
The TwitterLogin class, which is provided by flutter twitter login, accepts the consumerKey and consumerSecret that we obtained when we created the Twitter developer account.
final TwitterLogin twitterLogin = new TwitterLogin(
consumerKey: 'YOUR CONSUMER_KEY',
consumerSecret: 'YOUR SECRET_KEY',
);
This was a brief introduction to Twitter sign-in using Firebase authentication from my side and how it works using Flutter. I have described the fundamental architecture of Twitter sign In in the article; you are free to adapt this code as you see fit.
I’m hoping that the material on this blog will be adequate for you to try out Twitter Sign-In in your Flutter projects. Please give this demo programme a try to see how Twitter Sign-In with Firebase Authentication works with flutter.
Go to the official Go website and download the appropriate installation file for your operating system.
Run the installer and follow the instructions to complete the installation.
install go language in windows
Hello World Program in Go Language
1. Create a Folder in Desktop or anywhere.
2. Open the Folder in any Text Editor (Sublime Text or VSCode).
3. Create a file names “hello_world.go”, Here go is golang file extension.
paste below hello world code
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
you name get error near package main saying “go.mod file not found”, It’s because go language module is not initialized to hello_world.go file, To add the file into go.mod run below cmd as shown in step 4.
4. Open Terminal in IDE
go mod init hello_world.go
This will create a go.mod file and add the file into it.
run go program go run hello.go
create a executable file go build hello_world.go
run the exe file .\hello_world.exe
Video on Installing Go lang and hello world program
Hi Guys, In this dart article let’s checkout How to get ASCII code from a Character or String from a ASCII code in dart language (will also work in Flutter programming).
What is ASCII?
ASCII stands from American Standard Code from Information Interchange, ASCII is a encoding standard character that use 7 bit binary code basically to represent 128 possible character, which include characters like digits, letters, punctuation marks & control Code.
Eg:- A ASCII code for letter capital ‘A’ is 65 & for small ‘a’ = 97, Likewise ASCII code for digit 0 is 48.
void main() {
String message = "This is Example to get ASCII code from String";
List<int> asciiCodes = [];
for (int i = 0; i < message.length; i++) {
asciiCodes.add(message.codeUnitAt(i));
}
print(asciiCodes);
}