Home Blog Page 76

Flutter provider for beginners tutorial with app example

3
Flutter Provider tutorial example using changeNotifierProvider
Flutter Provider tutorial example using changeNotifierProvider

Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we gonna learn about Provider in Flutter.

Here is Official Library document https://pub.dev/packages/provider

What is Flutter Provider?

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.

why setstate method in flutter is not good for huge UI update

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 :

Flutter provider flowchart example
  • 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)

Homepage.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_provider/Timer_Data.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  var remaining = 10;

  @override
  void initState() {
    // TODO: implement initState

    Timer.periodic(Duration(seconds: 1), (j){
      setState(() {
        remaining --;
      });

      if(remaining == 0)
        {
          j.cancel();
        }


    });

    Timer.periodic(Duration(seconds: 1), (t){

      var timeinfo = Provider.of<Timer_Data>(context,listen: false);

      timeinfo.updateRemainingTime();

      print(timeinfo.gettime_remain_provider());

      if(timeinfo.gettime_remain_provider() == 0)
        {

          t.cancel();
        }


    });
    super.initState();


  }
  @override
  Widget build(BuildContext context) {

    print("Rebuilt... complete UI... Not Good for Flutter Engine");
    return Scaffold(
      appBar: AppBar(title: Text("Flutter Provider Example"),),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("With setState property",style: TextStyle(fontSize: 20),),
            Text("$remaining",style: TextStyle(fontSize: 30),),
            
            SizedBox(height: 25,),
            
            Text("By using providers",style: TextStyle(fontSize: 20),),
            Consumer<Timer_Data>(builder: (context, data,child) {
              return Text(data.gettime_remain_provider()?.toString()?? " ",style: TextStyle(fontSize: 30),);
            },)
          ],
        ),
      ),
    );
  }
}

Step 5: create instance using ChangeNotifierProvider in main.dart

This ChangeNotifier Provider will create a instance of Data_Model and then we can easily use the instance value any where inside it’s child widget.

import 'package:flutter/material.dart';
import 'package:flutter_provider/HomePage.dart';
import 'package:flutter_provider/Timer_Data.dart';
import 'package:provider/provider.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(

        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: ChangeNotifierProvider(create: (BuildContext context) =>Timer_Data(),
      child: HomePage()),
    );
  }
}


Result

Flutter Provider Example

Conclusion

In this Tutorial we learnt basic of flutter provider example – Flutter Application development

Related Articles

Firebase Login using Flutter Provider

Android Jetpack Compose tutorial with State management Example

2
Android Jetpack Compose basic tutorial with example
Android Jetpack Compose basic tutorial with example

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

  1. Composable
  2. Model
  3. 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

Download Canary version from here https://developer.android.com/studio/preview?authuser=1

Project Creation

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

jetpack compose build.gradle

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

jetpack compose state management tutorial 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.

Any Question/Query please do comment below

Thank You

flutter swiper – image slider/swiper in flutter

0
Image slider in flutter swiper library
Image slider in flutter swiper library
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.

Flutter Swiper Example

Installation of dependencies

Add library in pubspec.yaml file

dependencies:
  flutter_swiper: ^1.1.6  #add this line 

After adding hit pub get button

Importing it where required

import 'package:flutter_swiper/flutter_swiper.dart';

so now you can implement swiper widgets in your flutter project.

Widgets Snippets Code With  Outputs

#DEFAULT

swiper flutter

 

 

 

 

 

//flutter Swipper default
              Container(
                height: 200,
                width: MediaQuery.of(context).size.width/2-2,
                child: new Swiper(

                  itemBuilder: (BuildContext context, int index) {
                    return new Image.network(
                      imagedatamodel[index].postphoto,
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: imagedatamodel.length,
                  itemWidth: 300.0,
                  layout: SwiperLayout.DEFAULT,
                ),
              ),

 

#STACK

flutter swiper stack

 

 

 

 

//flutter Swipper Stack
              Container(
                height: 200,
                width:  MediaQuery.of(context).size.width/2,
                child: new Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    return new Image.network(
                      imagedatamodel[index].profilepic,
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: imagedatamodel.length,
                  itemWidth: 300.0,
                  layout: SwiperLayout.STACK,
                ),
              ),

#TINDER

flutter tinder swiper

 

 

 

 

//flutter Swipper Tinder
          Swiper(
            itemBuilder: (BuildContext context, int index) {
              return new Image.network(
                imagedatamodel[index].profilepic,
                fit: BoxFit.fill,
              );
            },
            itemCount: imagedatamodel.length,
            itemWidth: 200.0,
            itemHeight: 200.0,
            layout: SwiperLayout.TINDER,
          ),

#CUSTOM WITH ANIMATION

flutter swipe animation – flutter swiper custom pagination

flutter swipe animation

//flutter swiper with custom animation
          Swiper(
              layout: SwiperLayout.CUSTOM,
              customLayoutOption: new CustomLayoutOption(
                  startIndex: -1,
                  stateCount: 3
              ).addRotate([
                -45.0/180,
                0.0,
                45.0/180
              ]).addTranslate([
                new Offset(-340.0, -40.0),
                new Offset(0.0, 0.0),
                new Offset(340.0, -40.0)
              ]),
              itemWidth: 300.0,
              itemHeight: 200.0,
              itemBuilder: (context, index) {
                return new Container(
                  color: Colors.blue[400],
                  child: new Center(
                    child: new Text("$index",style: TextStyle(color: Colors.black,fontSize: 20),),
                  ),
                );
              },
              itemCount: 10),

 

Complete Code Swiper in Flutter

just copy the below code and paste in main.dart of you flutter for testing the working of this library

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

import 'package:flutter_swiper/flutter_swiper.dart';
import 'Image_DataModel.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primaryColor: Colors.blue,

      ),
      home: new MyHomePage(title: 'Flutter Swiper Example'),
      debugShowCheckedModeBanner: false,

    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body:  Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          SizedBox(
            height:5
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,

            children: [

              //flutter Swipper default
              Container(
                height: 200,
                width: MediaQuery.of(context).size.width/2-2,
                child: new Swiper(

                  itemBuilder: (BuildContext context, int index) {
                    return new Image.network(
                      imagedatamodel[index].postphoto,
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: imagedatamodel.length,
                  itemWidth: 300.0,
                  layout: SwiperLayout.DEFAULT,
                ),
              ),
              SizedBox(width: 2,),
              //flutter Swipper Stack
              Container(
                height: 200,
                width:  MediaQuery.of(context).size.width/2,
                child: new Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    return new Image.network(
                      imagedatamodel[index].profilepic,
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: imagedatamodel.length,
                  itemWidth: 300.0,
                  layout: SwiperLayout.STACK,
                ),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,

            children: [
              Text("Swiper Default",style: TextStyle(fontSize: 15),),
              Text("Swiper Stack",style: TextStyle(fontSize: 15),)
            ],
          ),
          //flutter swiper with custom animation
          Swiper(
              layout: SwiperLayout.CUSTOM,
              customLayoutOption: new CustomLayoutOption(
                  startIndex: -1,
                  stateCount: 3
              ).addRotate([
                -45.0/180,
                0.0,
                45.0/180
              ]).addTranslate([
                new Offset(-340.0, -40.0),
                new Offset(0.0, 0.0),
                new Offset(340.0, -40.0)
              ]),
              itemWidth: 300.0,
              itemHeight: 200.0,
              itemBuilder: (context, index) {
                return new Container(
                  color: Colors.blue[400],
                  child: new Center(
                    child: new Text("$index",style: TextStyle(color: Colors.black,fontSize: 20),),
                  ),
                );
              },
              itemCount: 10),
          Center(child: Text("Swiper with Custom Swipe Animation"),),

          //flutter Swipper Tinder
          Swiper(
            itemBuilder: (BuildContext context, int index) {
              return new Image.network(
                imagedatamodel[index].profilepic,
                fit: BoxFit.fill,
              );
            },
            itemCount: imagedatamodel.length,
            itemWidth: 200.0,
            itemHeight: 200.0,
            layout: SwiperLayout.TINDER,
          ),
          Center(
            child: Text("Swiper Tinder",style: TextStyle(fontSize: 15),),
          ),

        ],

      ),
    );
  }
}

Constructor of this library

Basic

Parameter Default Description
scrollDirection Axis.horizontal If Axis.horizontal, the scroll view’s children are arranged horizontally in a row instead of vertically in a column.
loop true Set to false to disable continuous loop mode.
index 0 Index number of initial slide.
autoplay false Set to true enable auto play mode.
onIndexChanged void onIndexChanged(int index) Called with the new index when the user swiped or autoplay
onTap void onTap(int index) Called when user tap ui.
duration 300.0 The milliscends of every transaction animation costs
pagination null set new SwiperPagination() to show default pagination
control null set new SwiperControl() to show default control buttons

 

Check out official Site to study in details here https://pub.dev/packages/flutter_swiper

Android Life Cycle Activity

0
Android activity life cycle
Android activity life cycle

Hi Guys, Welcome to Proto Coders Point, In the Android Article we will discuss on the LifeCycle of android Activity.

Android App Lifecycle – Android Activity Lifecycle

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

android activity lifecycle flowchart
android activity lifecycle flowchart

Activity lifecycle program in android studio

Create a new Android Project in android studio with Empty Activity.

then just copy paste the respective source codes

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

package com.example.androidlifecycle;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("lifecycle","onCreate invoked");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("lifecycle","onStart invoked");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("lifecycle","onResume invoked");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("lifecycle","onPause invoked");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("lifecycle","onRestart invoked");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("lifecycle","onStop invoked");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("lifecycle","onDestroy invoked");
    }
}

Logcat output

android lifecycle logcat output
android lifecycle logcat output

Conclusion

In the Android Article we learnt what is an android activity and the LifeCycle of Activity.

Flutter Instagram UI Clone – Stories and New Feeds

0
Flutter Instagram UI Clone

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

Flutter Instagram UI design clone

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

add instagram logo image in assets folder

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

instagram text logo
download this image and paste it in your image directory

Here is my project structure after adding image and giving path to the image directory.

creating folder in flutter and setting path in pubspec yaml file

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

  1. HomePage.dart
  2. InstaBody.dart
  3. InstaStories.dart
  4. InstaList.dart

#1. HomePage.dart

This Home Page simply has a appbar, body and bottom navigation bar

Instagram UI clone

import 'package:flutter/material.dart';
import 'package:flutter_instagram_ui/InstaBody.dart';

class HomePage extends StatelessWidget {

  final AppTopBar = new AppBar(
    backgroundColor: Color(0XFFF8faf8),
    elevation: 1.0,
    centerTitle: true,
    leading: Icon(Icons.camera_alt),
    title: SizedBox(height: 35.0,child: Image.asset("assets/images/instatexticon.png")),
    actions: <Widget>[
      Padding(
        padding: EdgeInsets.only(right: 12.0),
        child: Icon(Icons.send),
      )
    ],
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
appBar: AppTopBar,
      body: InstaBody(),
      bottomNavigationBar: Container(
        color: Colors.white,
          height: 58.0,
         alignment: Alignment.center,
        child: BottomAppBar(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
               IconButton(
                icon: Icon(Icons.home),
                onPressed: (){

                },
              ), IconButton(
                icon: Icon(Icons.search),
                onPressed: null
              ),
              IconButton(
                icon: Icon(Icons.add_box),
                onPressed: null
              ),
              IconButton(
                icon: Icon(Icons.favorite),
                onPressed:null
              ),
              IconButton(
                icon: Icon(Icons.person),
                onPressed: null
              ),
            ],
          ),
        ),
      ),
    );
  }
}

#2. InstaBody.dart

This widget page simple return a Column widget which has a children widget i.e Flexiable which in turn have child as InstaList.dart page

import 'package:flutter/material.dart';

import 'InstaList.dart';
class InstaBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Flexible(
          child: InstaList(),
        )
      ],
    );
  }
}

#3. InstaStories.dart

Instagram story UI design

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

class InstaStories extends StatelessWidget {

  final storyText = Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Text("Stories",style: TextStyle(fontWeight: FontWeight.bold ),),
      Row(
        children: [
          Icon(Icons.play_arrow),
          Text("Watch All",style: TextStyle(fontWeight: FontWeight.bold),)
        ],
      )
    ],
  );

  final storyProfile = Expanded(
    child: ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: dummyStoryData.length,
      itemBuilder: (context,index)=>Stack(
        alignment: Alignment.bottomRight,
        children: [
          Container(
            width: 60.0,
            height: 60.0,
            decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                  fit: BoxFit.fill,
                  image:NetworkImage(dummyStoryData[index].profilepic),

                )
            ),
            margin: const EdgeInsets.symmetric(horizontal: 8.0),
          ),
          index == 0 ? Positioned(
            right: 10.0,
            child: CircleAvatar(
              backgroundColor: Colors.blueAccent,
              radius: 10.0,
              child: Icon(Icons.add,size: 14.0,
                color: Colors.white,),
            ),
          ): Container()
        ],
      ),
    ),
  );
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisAlignment: MainAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          storyText,  //check above image for understanding
          storyProfile
        ],
      ),
    );
  }
}

#4. InstaList.dart

Instagram HomePage UI design Clone

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_instagram_ui/InstaStories.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'Data_Model_Story.dart';

class InstaList extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    var deviceSize = MediaQuery.of(context).size;
    return ListView.builder(itemCount:dummyStoryData.length,itemBuilder: (context,index)=> index == 0 ? SizedBox(
      child: InstaStories(),
      height: deviceSize.height *0.15,
    ):Column(
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        
        //1st row
        
        Padding(
          padding: const EdgeInsets.fromLTRB(16.0,16.0,8.0, 16.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
             children: [
              Row(
                children: [
                  Container(
                    height: 40.0,width: 40.0,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      image: DecorationImage(
                          fit: BoxFit.fill,
                          image: NetworkImage(dummyStoryData[index].profilepic)
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 10.0,
                  ),
                  Text(dummyStoryData[index].name,style: TextStyle(fontWeight: FontWeight.bold),),
                ],
              ),

               IconButton(
                 icon: Icon(Icons.more_vert),
                 onPressed: null,
               )

             ],
          ),
        ),

        //2nd row


        InteractiveViewer(
          boundaryMargin: EdgeInsets.all(8.0),
          minScale: 0.1,
          maxScale: 1.6,
          onInteractionUpdate: (_)=>print("Interaction Updated"),
          child: ClipRRect(borderRadius: BorderRadius.circular(15),
              child: Flexible(
                fit: FlexFit.loose,
                child: Image.network(dummyStoryData[index].postphoto,fit: BoxFit.cover,),
              ),
          ),
        ),

        //3rd row
        
        Padding(
          padding: const EdgeInsets.all(16.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Icon(
                    FontAwesomeIcons.heart
                  ),
                  SizedBox(width: 10,),
                  Icon(
                    FontAwesomeIcons.comment
                  ),
                  SizedBox(width: 10,),
                  Icon(
                    FontAwesomeIcons.paperPlane
                  )
                ],
              ),
              Icon(
                FontAwesomeIcons.bookmark
              )
            ],
          ),
        ),

        //4th Row

        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Text(
            "Liked by Rajat Palankar and 568,444 others ",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
        ),
        
        //5th Row

        Padding(
          padding: const EdgeInsets.fromLTRB(16.0, 16.0, 8.0, 8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Container(
                height: 40.0,
                  width: 40.0,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  image: DecorationImage(
                      fit: BoxFit.fill,
                      image: NetworkImage(dummyStoryData[index].profilepic)
                  ),
                ),
              ),
              SizedBox(width: 10.0,),
              Expanded(
                child: TextField(
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: "Add a comment..."
                  ),
                ),
              )
            ],
          ),
        ),

// 6th row
      Padding(
        padding: const EdgeInsets.symmetric(horizontal: 16.0),
        child: Text("20 Minutes Ago",style: TextStyle(color: Colors.grey),) ,
      )
      ],
    ),);
  }
}

In the above source code i have added comment for example : //1st row //2nd row
just compare it with the above image.

Thus your Flutter Application is ready to show UI Design of Instagram Home page using Flutter dart.

5 Best Coding Books – Programming Books for Beginners

1
programmer books for beginners

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

By V. Anton Spraul

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.

From where to buy this Book ?

Buy Book From Amazon https://amzn.to/3g2zX6w


#2. Clean Code: A Handbook of Agile Software Craftsmanship

By Robert C. Martin

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.

From where to buy this Book ?

Buy Book From Amazon https://amzn.to/3kLVovQ


#3. The C Programming Language

By Brian W. Kernighan / Dennis Ritchie

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.

From where to buy this Book ?

Buy Book From Amazon https://amzn.to/2PPWjgT


#4. Java Book – The Complete Reference

By Herbert Schildt

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.

From where to buy this Book ?


Buy Book From Amazon https://amzn.to/3gVzl3R


#5. Python The Complete Reference

By  Martin C. Brown

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.

From where to buy this Book ?


Buy Book From Amazon https://amzn.to/2E28uo9


Computer Programming Crash Course: 7 Books in 1

Buy Book From Amazon https://amzn.to/3h0H40o


This are 5 top programming books for beginners that all developer must read and teach yourself how to think like a programmer.