In Short, Provider is like a way to use an InheritedWidget.
For Example: If any data gets changed and need to updated into the App UI, then Instead of rebuilding full hierarchy of Widgets, we can simply Update value of Flutter Provider Consumer Widgets.
Video Tutorial
Below Example is by using setState() method
Using setState method is good when there is Small UI data change.
Normally by making us of setState() method whole application UI gets rebuilt and continuously keeps rebuilding full application which is not a good sign to be a Flutter developer and this may give lots of load to the flutter engine (which may led to app performance issue).
As you can see in above screenshot: i have made use of Count timer to decrement a variable value then simple display the updated variable value into the UI
Here Count down will be from 10 – 0, and every 1 second decrement the value by 1 and as value gets updated, whole app UI gets rebuilt for 10 time
You can view the logcat print statement above.
For a simple application which has very few data change/update then, it’s fine to make use of setState() method, but it is better to make use of other method like flutter provider when it comes for complex application build.
Flutter provider tutorial and Explaination
In provider we have 3 important part that are :
ChangeNotifierProvider
Update/ChangeNotifier
Consumer
ChangeNotifierProvider : which creates the instance of your data, as you can see in above diagram changeNotifierProvider will create instance of DataModel class
Update: from any where inside your page you want to update the value, you just get instance of that provider and manupulate that value as per and then as soon as the value is been change, data model will notify all the Flutter Consumer widgets.
And then once the consumer get Notified about the data change, you can update your widget as per.
Flutter provider tutorial with Example
Step 1: Creating a new Flutter Project
Step 2: Open pubspec.yaml file and add the dependencies
dependencies:
provider: ^4.3.2+2 #latest version check official site
Step 3: Create a new Dart file in lib directory
After adding dependencies, then create a new dart file in lib directory on your flutter project
then name it as “Timer_Data.dart”
Timer_Data.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
class Timer_Data extends ChangeNotifier
{
int _time_remain_provider=11; // initial value of count down timer
int gettime_remain_provider() => _time_remain_provider; //method to get update value of variable
updateRemainingTime(){
_time_remain_provider --; //method to update the variable value
notifyListeners();
}
}
In above source we have a variable that holds initial value,
then there is a method that gets updated value of variable
and then it has updateRemainingTime() method that will decrement the value by -1.
Step 4: Create one more dart file for UI Design (Homepage.dart)
Hi, Guys Welcome to Proto Coders Point, In this android tutorial, we will learn about android jetpack compose and will build a simple app using state management (MutableState) in jetpack that will update UI when State or Variable value changes on button click.
Android Jetpack Compose tutorial – A declarative UI Toolkit
What is Android Jetpack Compose?
A Jetpack compose is a modern toolkit using which we can build a Native android UI Application, It’s based on the declarative programming model, so all you need is to simply describe how your app UI should look like and the compose will take care of the rest of app state changes, and UI gets Automatically Changed.
What do we mean by declarative UI?
Declarative UI means the developer can design the UI by the means of Programming Code, This Android Jetpack compose is been inspired by React.js and Flutter development.
Why Compose Jetpack?
Easy way to Explain you :
Whenever we design a screen in android we are making use of XML to create UI design & then giving functionality to the UI using code in Java or kotlin.
Fewer Lines of Code
No XML Needed
When we use Android JetPack compose there is no need to write XML UI Files, we just need to write the whole UI Code in Kotlin language itself.
Building Block of jetpack
Composable
Model
Preview
If you are designing a UI using jetpack compose, then you are basically writing function by making use of @Composable,
Then to check the preview display of your android application UI design in the android studio preview section you just need to add @Preview on top of @Composable.
A Composing is a function whatever we write in it get printed on the mobile screen as a widget view.
Note: As in Flutter all everything is a widget likewise in android jetpack every view is a widget
For Now, Android-Studio Stable version does not support Jetpack Compose so you need to make use of the Android Studio Canary version
Start Android-Studio and create a new Android project and in the Template section select “Empty Compose Activity” then finish building a project
Now, Let’s go into build.gradle file & check what new is been added for the Android Jetpack Compose project
As you can see in the below screenshot of build.gradle file everything is same as in normal android project except, you can see highlighted, there is a new thing that is integrated.
There are 2 new things you would see in this Gradle file
the first is to build features with compose as true
second, there are 3 new dependencies added. UI, material, tooling
Android jetpack android example – Increment number on Button Click
MainActivity.kt
package com.example.myapplication
import android.os.Bundle
import android.text.Layout
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.state
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.TextUnit
import androidx.ui.tooling.preview.Preview
import com.example.myapplication.ui.MyApplicationTheme
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme() {
MyApp()
}
}
}
@Preview
@Composable
private fun MyApp() {
setupStateUsingState()
}
@Composable
private fun setupStateUsingState() {
Column {
//Using MutableState in Compose
var counterState: MutableState<Int> = state { 0 }
TopAppBar(
title = { Text(text = "State Management") }
)
Text(
text = "Clicked: ${counterState.value}",color = Color.White,fontSize = TextUnit.Sp(20)//set new value
)
Button(onClick = {
//update value
counterState.value +=1
}) {
Text(text = "Click to Add by +1")
}
}
}
}
Output
As you can see in the above kotlin code,
I have created a @Composable function by the name “MyApp()” and this, in turn, calls another Composable function names “setupStateUsingState()”
It has a Column widget that has 3 children, i.e TopAppBar, Text, and a Button
Then, I have a variable of MutableState dataType Int initial value is set to 0.
And The value is printed into Text Widget.
whenever the user clicks on the button the variable counterState gets incremented by +1 and the changed value is printed on the screen.
Hi Guys, Welcome to Proto Coders Point, In this Flutter tutorial we will discuss on flutter swiper Library
What is flutter swiper? how to implement swiper in flutter?
A Swiper in simple words is a modern touch slider using which user of mobile application can slide any view like image Slider.
Swiper is been used on websites and mobile applications.
In Flutter there is a best library to integrate Swiper, with can be customized with multiple layouts and infinite loop, and as said in official library site that is compatible with Both Android and iOS.
Let’s begin implementation of this flutter library.
Installation of dependencies
Add library in pubspec.yaml file
dependencies:
flutter_swiper: ^1.1.6 #add this line
Android App Lifecycle is been build by 7 methods which are in android.app.Activity class library.
What is Activity in android? An activity is a page or a screen in android application where application user create different Event. An activity is same like window or frame of java.
The 7 android lifecycle method of Activity class, will instruct the app how to behave at particular states.
Android activity lifecycle methods
Then, let’s learn the 7 lifecycle methods in android activity.
Method
Description
onCreate ()
called when app Activity is first started.
onStart()
called when activity is been ready to show to users.
onResume()
called when activity start interacting with users.
onPause()
called when user switch to other app, or when user minimize the app
onStop()
called when activity is not visible to user.
onRestart()
After activity is stoped and user reopens the app.
onDestroy()
called when user close the app.
Android activity lifecycle diagram
Activity lifecycle program in android studio
Create a new Android Project in android studio with Empty Activity.
Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial we gonna build Instagram UI Clone using Flutter.
The many focus of this tutorial is to create a Instagram UI Clone and interactions with New feed in home page (post), For the project i have dummy data model to show it in insta UI
take a look at what instagram ui design look, below
So let’s begin creating instagram app ui in flutter development
Flutter Instagram UI Clone – Stories and New Feeds
OffCourse 🤣🤣 you need to create a new Flutter project in your IDE, In my case i am making use of android studio as my IDE to develop Flutter application.
Create a new Flutter project > Give a good name for you project (Flutter Instagram IU Clone) and next to finish the creating of flutter project.
#1. Adding instagram logo and font_awesome_flutter dependencies
first of all create a new assets/images folder under your flutter project and copy/paste a instagram text logo under that project and after adding the image path to that image in pubspec.yaml file
instagram text logo
Here is my project structure after adding image and giving path to the image directory.
Even you need font_awesome_flutter: dependencies to be added into your flutter project so that you can use it to show icons, as you can see i have added in above image.
Now we are done with all the requirement, Then now let’s start writing the flutter code to build instagram IU clone.
#2. Insta Data model
Create a new Dart file in lib directory of you project and name it as:
Data_Model_Story.dart
class Data_Model_Story {
final String name;
final String profilepic;
final String postphoto;
Data_Model_Story({this.name, this.profilepic,this.postphoto});
}
// dummy data to show Profile post and story image and Name of the account user.
List<Data_Model_Story> dummyStoryData = [
new Data_Model_Story(
name: "Rajat Palankar",
postphoto: "https://d1kkg0o175tdyf.cloudfront.net/large/m_d2c4766b1ede-2019-01-27-14-00-16-000106.jpg",
profilepic:
"https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg"),
new Data_Model_Story(
name: "BB ki Vines",
postphoto: "https://i.gadgets360cdn.com/large/bb_ki_vines_body_1579760395127.jpg",
profilepic:
"https://images-na.ssl-images-amazon.com/images/I/711q+ma1FQL.png"),
new Data_Model_Story(
name: "ashishchanchlani",
postphoto: "https://assets.entrepreneur.com/content/3x2/2000/20200217104953-Ashish1.jpeg",
profilepic:
"https://yt3.ggpht.com/a/AATXAJwZGPuuePGI6Mr887w6f6ZxsnoDl-Xf10gKPKIOeg=s900-c-k-c0xffffffff-no-rj-mo"),
new Data_Model_Story(
name: " Angry Prash",
postphoto: "https://pbs.twimg.com/media/D1tL281XcAAAAd1.jpg",
profilepic:
"https://pbs.twimg.com/profile_images/1143239373489463296/Zv3BvjsA.jpg"),
new Data_Model_Story(
name: "carryminati",
postphoto: "https://i.ytimg.com/vi/zzwRbKI2pn4/maxresdefault.jpg",
profilepic:
"https://m.media-amazon.com/images/M/MV5BM2NlNzUyODUtZDgyNS00ZjU3LWI5NGUtOWFkYmQwMGVlNGRmXkEyXkFqcGdeQXVyMTE2MTc3MzU1._V1_.jpg"),
new Data_Model_Story(
name: "Leo",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2016/11/29/02/28/attractive-1866858__340.jpg"),
new Data_Model_Story(
name: "Jack",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2017/06/26/02/47/people-2442565__340.jpg"),
new Data_Model_Story(
name: "Amelia",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2018/01/24/19/49/people-3104635__340.jpg"),
new Data_Model_Story(
name: "Sophia",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2017/11/23/07/47/babe-2972221__340.jpg"),
new Data_Model_Story(
name: "Harry",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2018/02/21/15/06/woman-3170568__340.jpg"),
new Data_Model_Story(
name: "Isla",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2016/01/19/18/04/man-1150058__340.jpg"),
new Data_Model_Story(
name: "Emily",
postphoto: "https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
profilepic:
"https://cdn.pixabay.com/photo/2015/07/31/15/01/man-869215__340.jpg"),
];
This Dummy data contain only name of Instagram Profile, His ProfilePic and postpic urls.
We can use this data to show in our Insta UI Clone app.
#3. main.dart file
import 'package:flutter/material.dart';
import 'package:flutter_instagram_ui/HomePage.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.black,
primaryIconTheme: IconThemeData(color: Colors.black),
primaryTextTheme: TextTheme(title: TextStyle(color: Colors.black))
),
home: HomePage(),
);
}
}
#4. Create 4 dart file for different Instagram UI View
HomePage.dart
InstaBody.dart
InstaStories.dart
InstaList.dart
#1. HomePage.dart
This Home Page simply has a appbar, body and bottom navigation bar
Hi Guys, Welcome to Proto Coders Point, In the article post we will discuss on 5 best programming books for beginners by which you can teach yourself and learn to think like a programmer and crack can any coding interview.
As any beginner in the Coding field, It’s very important to have a basic knowledge of coding/programming. Since there are many books that are good and available to buy from Amazon or Flipkart and this company even provides read online books for free, But selecting the right book seems to be difficult to deal with.
So Here i am with some top coding books for beginners, which all programmers must have read:
5 Best Coding Books – Programming Books for Beginners
#1. Think Like a Programmer – An Introduction to Creative Problem Solving
Anton Spraul says : The real challenge of programming isn’t learning a language’s syntax—it’s learning to creatively solve.
The Author V.Anton Spraul his main focus is on how to think like a programmmer, this unique book for coders will break down the way any programmers tends to solve coding issues. In this book there is a problem solving methods where a programmers can test their programming skill and knowlegde.
This book will help you in learning the systematic and Clean Code: Usually when beginner code any function it will work perfectly but then the same code is been sent to other programmer he might be difficult for him to understand because the code is full of messy and with no proper comments – this book Clean Code will help you to teach yourself how to write clean code.
The C Programming language book will elaborate you on the basic of procedure oriented programming and the basic fundamental of writing C programming codes.
It gives introduction on what are variables, loops and function that will give a quick start to beginner programmers.
c programming books for beginners, must read this book.
This is the most popular book on java programming, Whether you’re a java beginner or an experienced person this is the one and only book that has full details on Java course.
you can jump to learn python the hard way is you have basic knowlegde of any programming.
This book is the complete reference, it has overall information and detailed study of python so it’s the best python book and one of the best book for python for beginners to learn in-depth.