Home Blog Page 77

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.

Flutter Interactive Viewer widget – Flutter V 1.20

0
Flutter Interactive Viewer example
Flutter Interactive Viewer example

Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial we will build an application to demonstrate new feature of Flutter 1.20 that is Flutter Interactive Wiewer Widget.

What is Interactive Viewer Flutter?

Recently on August 4th 2020 Flutter team have launched V1.20, that comes with awesome developement tools.

one of it is Flutter Interactive Viewer

This Interactive Viewer is designed for developing simple & commonly interaction that happens into your application, such as Pan, Zooming or drag n drop events and using this widget user can easily resize the widget child.

Basically Interactive Viewer class is a widget that let’s us with the feature of  pan(Drag),Zooming with 2 finger touch.

flutter 1.20 dart 2.9.0
flutter 1.20 dart 2.9.0

Implementation of interactive viewer in android-studio(IDE)

So Let’s Implement it in our flutter project

Step 1: Create a new flutter project

I am using Android-Studio as my IDE to build Flutter Apps, you my make use of Android-studio or VSCode editor.

File > New > New Flutter Project

Give a name to the project as per your choose and continue.

Explanation of Flutter Interactive Viewer (Snippet Code)

Here is the basic explanation of each properties used in below snippet code.

InteractiveViewer(
                    boundaryMargin: EdgeInsets.all(20.0),
                    transformationController: transformationController,
                    
                    minScale: 0.1,
                    maxScale: 1.6,

                    // You can off zooming by setting scaleEnable to false
                    //scaleEnabled: false,
                    onInteractionStart: (_)=>print("Interaction Started"),
                    onInteractionEnd: (details) {
                      setState(() {
                        transformationController.toScene(Offset.zero);
                      });
                    },
                    onInteractionUpdate: (_)=>print("Interaction Updated"),
                    child: ClipRRect(borderRadius: BorderRadius.circular(15),child: Image.network("https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg")),
                  )

boundrymargin: it is just to define the space or margin from all the sides of the interactive viewer child.

minScale: here minimun scale means how much a uses can zoom out the widget, here 0.1  for example means 10% scale of the widget.

maxScale: Basically the maximum size that the widget can be Zoomed in by the user.

onInteractionStart: what event should occur when user try to interact with the widget either when user try to zoom or when user try to drag the widget.

OnInteractionUpdate: what event/function should occur when user drag or zoom the widget to new view/position.

OnInteractionEnd: when user drag and drop or when user simple interaction with widget leave free the widget, what event should happens

for example: when user zoom the image and then leave it, onInteractionEnd will get triggered and event like image get auto resized back to its original position.

In above Snippet code, in child tag we have a image widget that will simply load image from internet using IMAGE URL.

Step 2: Complete code of Flutter Interactive Viewer

Then in main.dart file under lib directory of you flutter project just copy below full code and run the project.

main.dart

import 'package:flutter/cupertino.dart';
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(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final transformationController = TransformationController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Interactive Viewer"),),
      backgroundColor: Colors.black38,
      body: Center(
        child: Container(
          width: MediaQuery.of(context).size.width-50,
          height: MediaQuery.of(context).size.height-250,
          child: Card(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ListTile(
                    leading: ClipRRect(borderRadius: BorderRadius.circular(50.0),child: Image.network("https://protocoderspoint.com/wp-content/uploads/2019/10/mypic-300x300.jpg")),
                    title: Text(" Rajat Palankar",style: TextStyle(fontSize: 15,fontWeight: FontWeight.bold),),
                    subtitle: Row(
                      children: [
                        Text("Just Now",style: TextStyle(fontSize: 12),),
                        SizedBox(width: 10,),
                        Icon(Icons.public,size: 15,color: Colors.grey,)
                      ],
                    ),
                    trailing: Icon(Icons.more_horiz),
                  )
                ),

                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: InteractiveViewer(
                    transformationController: transformationController,
                    boundaryMargin: EdgeInsets.all(20.0),
                    minScale: 0.1,
                    maxScale: 1.6,

                    // You can off zooming by setting scaleEnable to false
                    //scaleEnabled: false,
                    onInteractionStart: (_)=>print("Interaction Started"),
                    onInteractionEnd: (details) {
                      setState(() {
                        transformationController.toScene(Offset.zero);
                      });
                    },
                    onInteractionUpdate: (_)=>print("Interaction Updated"),
                    child: ClipRRect(borderRadius: BorderRadius.circular(15),child: Image.network("https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg")),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ListTile(
                    leading: Column(children: [Icon(Icons.thumb_up,color: Colors.blue,),Text("110K",style: TextStyle(fontSize: 12),)],),
                    title: Column(children: [Icon(Icons.message,color: Colors.green,),Text("1201",style: TextStyle(fontSize: 12))],),
                    trailing: Column(children: [Icon(Icons.share,color: Colors.blue,),Text("500",style: TextStyle(fontSize: 12))],),
                  ),
                )
              ],
            ),
          ),
        ),
      )
    );
  }
}


Recommended Articles learn more

Integration of Google Maps in Flutter

Flutter Photo View widget with zoomable image gallery

Flutter provider login example – Firebase login registration using Provider

Development made easy with GetX Plugin

How to show custom toast in android example – toast message android

0

Hi Guys, Welcome to Proto Coders Point, In this android tutorial we will create our own custom toast message in android studio.

What is Toast Message?

Some TImes Toast Messages are also called as Toast Notification.

It’s a small message that pop up at the bottom of the device screen and immediately disappears on it’s own after a delay of few seconds.

This are mostly used to show a feedback on the operation that is preformed by the user.

So, Let’s Begin Implementing of Custom Toast Message into our android project.

Step 1: Create a new project in android studio

File > New > New Project

Give a name to your project as “android custom toast” and hit the next,next finish so that android studio can build a project for you.

Step 2: Create 2 vector image in Drawable folder

As we gonna show 2 toast message i.e Smiling face icon when success toast message and a Error icon when unsuccessful message. So that we need to create 2 vector image in drawable folder

Right Click ( drawable folder ) > New > Vector Image ( select vector image and color and save it )

how to create vector image in android studio

Step 3: Create a layout design for custom toast message

create a new layout file under res > layout and name it as custom_toast_design.xml and paste the below xml design code.

custom toast message android layout design code

 

custom_toast_design.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:drawable/dialog_holo_light_frame">

    <LinearLayout
        android:id="@+id/linearColor"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:background="#00cc00">

        <ImageView
            android:id="@+id/imageview"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_margin="15dp"
            android:background="@drawable/success"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">
        <TextView
            android:id="@+id/toast_message"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Toast message Here"
            android:layout_margin="10dp"
            android:textSize="15sp"
            android:textColor="@android:color/black"
            android:layout_gravity="center"
            android:gravity="center"
            android:textStyle="bold"/>
    </LinearLayout>


</LinearLayout>

Step 4: activitymain.xml ui code

In activitymain.xml we simple have 2 button that perform some events on click

1 button will display success toast message and 2nd button will displpay error toast message.

activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:gravity="center"
    tools:context=".MainActivity">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:textColor="@android:color/holo_blue_dark"
            android:text="Custom Toast message" />

    <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Show Success Toast"
            android:id="@+id/B_Success"/>

    <Button
            android:layout_width="wrap_content"
          android:layout_height="wrap_content"
         android:text="Show Error Toast"
         android:id="@+id/B_Error"/>


</LinearLayout>

Step 5: Show the custom Toast message in MainActivity

MainActivity.java

package com.example.custom_toast;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button success_toast,error_toast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        success_toast=(Button)findViewById(R.id.B_Success);
        error_toast=(Button)findViewById(R.id.B_Error);

        success_toast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //on success
                //here i m manually passing string and icon to the function
                showCustomToast("Success, Stored Successfully","#00cc00",R.drawable.success);
            }
        });

        error_toast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //on success
                //here i m manually passing string and icon to the function
                    showCustomToast("Error, Something went wrong","#ffff00",R.drawable.error);
            }
        });
    }

    //once function that show 2 different kind of toast message
    public void showCustomToast(String text,String color,int icon){
        View toast = LayoutInflater.from(this).inflate(R.layout.custom_toast_deisgn,null);
        Toast custom = new Toast(this);

        custom.setView(toast);

        TextView message = toast.findViewById(R.id.toast_message);
        //setting the color to linear layout
        LinearLayout linearLayoutcolor = toast.findViewById(R.id.linearColor);
        ImageView imageview = toast.findViewById(R.id.imageview);

        //setting the image icon
        imageview.setBackground(this.getResources().getDrawable(icon));

        linearLayoutcolor.setBackgroundColor(Color.parseColor(color));
        
        message.setText(text);
        custom.setDuration(Toast.LENGTH_SHORT);
        custom.show();
    }
}

 

Conclusion

This tutorial was on building your own custom toast message in android studio.

 

Related Post

Flutter toast

Flutter Bot Toast Library