Home Blog Page 83

Social Media Story View Page development using Flutter

0
Social Media Story View Page development using Flutter
Social Media Story View Page development using Flutter

Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we will make use of a Flutter Library “Story_View” using which you can easily create a whatsapp stories or instagram stories page.

Introduction to story view package library

Story View Flutter Library Widget is very useful for the Flutter developer, By using this library you can display Social media stories pages just like WhatsApp Status Story or Instagram Status Story View.

FINAL RESULT OF THIS LIBRARY

Features of StoryView Widget Library

You can add

  1. Simple Text Status story.
  2. Images Stories.
  3. GIF Images Stories.
  4. Video Stories( with caching enabled).
  5. Gesture for Previous,Next and Pause the Story.
  6. Caption for each story items.
  7. A animated Progress indicator on top of every story views

Let’s get Started with adding this library into your flutter project

Social Media Story View Page development using Flutter

Step 1 : Adding Story View dependencies into your flutter project

Open pubspec.yaml file and add the story view dependencies under dependencies section

dependencies:
  story_view: ^0.10.0   // add this line

Step 2: Import the story_view.dart file in main.dart

open main.dart file and import the class file in it

import 'package:story_view/story_view.dart';

Step 3: Creating StoryItem list and adding it to HomePage(main.dart) with widget

Create a storyController

final storyController = StoryController(); // used to control the media story

Generate a list of stories

//creating the list of Social media Storys
// Social Media Story List

  List<StoryItem> storyItemsList = [
    StoryItem.text("Hello Guys, 👉", Colors.blue[500]), //story 1
    StoryItem.text(
        "Welcome to Proto Coders Point, 👉", Colors.red[600]), //story 2
    StoryItem.pageImage(
        NetworkImage(
            "https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg"),
        caption: "THINK TWICE CODE ONCE"), //story 3

    StoryItem.pageImage(
        NetworkImage(
            "https://protocoderspoint.com/wp-content/uploads/2019/10/protocoderspoint-rectangle-round-.png"),
        caption: "HOPE THIS TUTORIAL HELP YOU"), //story 4
  ];

then, Add the storycontroller and story item list into StoryView() widget

StoryView(
       storyItemsList,  // this is list of StoryItems
       controller: storyController, 
       repeat: true,  // set it to false if 
       onComplete: () => print("STORY COMPLETED"), // what sould happen when story ends
     ),

Complete code Copy Paste it in main.dart file

main.dart

import 'package:flutter/material.dart';
import 'package:story_view/story_view.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',
      //removing debug banner
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage> {
  // lets start creating Social media Story view

  final storyController = StoryController(); // used to control the media story

  //creating the list of Social media Storys
// Social Media Story List

  List<StoryItem> storyItemsList = [
    StoryItem.text("Hello Guys, 👉", Colors.blue[500]), //story 1
    StoryItem.text(
        "Welcome to Proto Coders Point, 👉", Colors.red[600]), //story 2
    StoryItem.pageImage(
        NetworkImage(
            "https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg"),
        caption: "THINK TWICE CODE ONCE"), //story 3

    StoryItem.pageImage(
        NetworkImage(
            "https://protocoderspoint.com/wp-content/uploads/2019/10/protocoderspoint-rectangle-round-.png"),
        caption: "HOPE THIS TUTORIAL HELP YOU"), //story 4
  ];

  @override
  Widget build(BuildContext context) {
    return Material(
      child: StoryView(
        storyItemsList,
        controller: storyController,
        repeat: true,
        onComplete: () => print("STORY COMPLETED"),
      ),
    );
  }
}

Then, your flutter application is ready to show a Story page with 4 StoryItems.

For more in detail about this Story View Page Flutter library visit official here

WhatsApp Clone App UI Design using Flutter | Status Tab Page | PART 2

0
WhatsApp Clone App UI Design using Flutter Status Tab Page

Hi Guys, Welcome to Proto Coders Point, This is PART 2 of WhatsApp Clone UI using Flutter, In this part we will continue with clone designing Status Tab Page.

If you have not gone through the first part of WhatsApp UI Clone using Flutter, Then make sure to go through it. Here

Build a WhatsApp Clone App UI Design using Flutter | Material Design

FINAL RESULT OF THIS PART

Fine Then Let’s continue.

In last section i have forgot to remove FloatingActionButton from Other Tabs, In Other words FloatingActionButton(New Chat Button) Should be Visible only in ChatScreen, So we need to Disable the button when user navigate/swipe towords other screen.

Then, To do so Follow this steps:

Step 1: Add a bool variable

Open main.dart file or whatever you have names your homepage

bool showFloatingB = true;
Step 2: Replace the initState() 
@override
 void initState() {
   // TODO: implement initState
   super.initState();
   // total tab we are creating is 4 so : length is 4 : initialIndex is set to position 1
   _tabController = new TabController(length: 4, vsync: this, initialIndex: 1);

   _tabController.addListener(() {
     if (_tabController.index == 1) {
       setState(() {
         showFloatingB = true;
       });
     } else {
       setState(() {
         showFloatingB = false;
       });
     }
   });
 }
In InitState method, we are checking _tabController index using _tabController.addListener.

If _tabController.index == 1  then it’s chatScreen visible so we set the showFloatingB to true else, We set showFloatingB to false.

Step 3 : Now Replace FloatingActionButton Widget
floatingActionButton: showFloatingB ? FloatingActionButton(
              onPressed: () {
                print("Floating Button Clicked");
              },
              backgroundColor: Theme.of(context).accentColor,
              child: Icon(
                Icons.message,
                color: Colors.white,
              ),
            )
          : null,

Here, we are setting the FloatingActionButton to be visible only if the showFloatingB is true else floatingActionButton is set to null, that means floatingActionButton is not visible.

WhatsApp Clone App UI Design using Flutter Status Tab Page | PART 2

Step 1: WhatsApp UI  StatusPage Using Flutter

Now,Open StatusPage.dart file  and copy paste the below lines of code in it.

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

class Statuspage extends StatefulWidget {
  @override
  _StatuspageState createState() => _StatuspageState();
}

class _StatuspageState extends State<Statuspage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.grey[300],
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Card(
            color: Colors.white,
            child: Padding(
              padding: const EdgeInsets.all(10.0),
              child: ListTile(
                leading: Stack(
                  children: <Widget>[
                    CircleAvatar(
                      radius: 30,
                      backgroundImage: NetworkImage(
                          "https://cdn2.vectorstock.com/i/1000x1000/23/81/default-avatar-profile-icon-vector-18942381.jpg"),
                    ),
                    Positioned(
                      bottom: 0.0,
                      right: 1.0,
                      child: Container(
                        height: 20,
                        width: 20,
                        child: Icon(
                          Icons.add,
                          color: Colors.white,
                          size: 15,
                        ),
                        decoration: BoxDecoration(
                            color: Colors.green, shape: BoxShape.circle),
                      ),
                    ),
                  ],
                ),
                title: Text(
                  "My Status",
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                subtitle: Text("Tap to add status update"),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(
              "Viewed updates",
              style: TextStyle(color: Colors.grey, fontWeight: FontWeight.bold),
            ),
          ),
          Expanded(
              child: Container(
            padding: const EdgeInsets.all(8.0),
            color: Colors.white,
            child: ListView(
              children: <Widget>[
                ListTile(
                  leading: CircleAvatar(
                    radius: 30,
                    backgroundImage: NetworkImage(
                        "https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg"),
                  ),
                  title: Text(
                    "Rajat Palankar",
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  subtitle: Text(
                    " 45 minutes ago",
                  ),
                  onTap: () => Navigator.push(context,
                      MaterialPageRoute(builder: (context) => StoryPage())),
                )
              ],
            ),
          )),
        ],
      ),
    );
  }
}

Step 2: Add Story View Flutter library

Then, Now Open pubspec.yaml file, and add flutter depencencies for the story_view flutter library package.

dependencies:
  story_view: ^0.10.0

 

Step 3: Create a new dart file StoryPage.dart

right click on lib > New > dart file  and name it as StoryPage.dart

Then, Copy Paste the below lines of dart code.

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

class StoryPage extends StatefulWidget {
  @override
  _StoryPageState createState() => _StoryPageState();
}

class _StoryPageState extends State<StoryPage> {
  final storycontroller = StoryController();   //a controller for your story

  final List<StoryItem> storyItems = [
    StoryItem.text("Hello Guys, Welcome to Proto Coders Point",Colors.blue[500]), // Story 1
    StoryItem.pageImage(NetworkImage("https://protocoderspoint.com/wpcontent/uploads/2019/10/protocoderspoint-rectangle-round-.png")), //Story 2
    
    // you can add as many as whatsapp story in this list 
  ];
  @override
  Widget build(BuildContext context) {
    return Material(
      child: StoryView(
        storyItems,
        controller: storycontroller,
        inline: false,
        repeat: false,
        onComplete: () => Navigator.pop(context), // when storys ends , the StoryPage wil be poped from the view
      ),
    );
  }
}

There you go Part 2 is Completed, your Flutter  whatsapp clone Ui Design is ready to show ChatScreen and StatusScreen with WhatsApp Story Clone page.

Build WhatsApp Clone App UI Design using Flutter

3
Clone of whatsapp application UI Design using Flutter
Clone of whatsapp application UI Design

Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we will learn to build WhatsApp Clone App using Flutter – UI Design.

Final Result of this Project

whatsapp clone Ui design
whatsapp clone Ui design

Follow the below step to build/create a whatsapp clone using flutter.

or Watch the Video Tutorial on flutter whatsapp clone tutorial

Note this Article is devided in 3 parts for each tabs in whatsapp app Status bar clone, whatsapp Call Tab

Step 1: Create a new Flutter Project

OffCourse you need to create a new Flutter Project or Open any Existing Project,

In my Case, I am making use of Android Studio as my IDE to Build WhatsApp Clone UI.

How to create new Flutter Project in android Studio?

File > New > New Flutter Project > Give a name to your project ” Whatsapp Clone UI Design”

Step 2: Create new package “Data_Model” and create a “Chat_Data_Model”

Right Click on lib > New > Package name the package as “Data_Model” or anything as per your choice.

package directory creation in flutter project
package directory creation in flutter project

Then you need a class Data Model that holds list of Dummy Chat list so

Under “Data_Model” directory create a new dart file named “Chat_Data_Model.dart”

chat_data_model

Then, Paste the below code

Chat_Data_Model.dart

This contains dummy data list of whatsapp chat details like

  • name,
  • message,
  • time,
  • and profile picture
class Chat_Data_Model {
  final String name;
  final String message;
  final String time;
  final String profilepic;

  Chat_Data_Model({this.name, this.message, this.time, this.profilepic});
}

// dummy data for chats page  listview

List<Chat_Data_Model> dummyData = [
  new Chat_Data_Model(
      name: "Rajat Palankar",
      message: " Hi... Whatsapp How are you ?",
      time: "04:30 AM",
      profilepic:
          "https://pbs.twimg.com/profile_images/1243950916362895361/Z__-CJxz_400x400.jpg"),
  new Chat_Data_Model(
      name: "Oliver Wyman",
      message: " Wassup Bro",
      time: "04:30 AM",
      profilepic:
          "https://www.oliverwyman.com/content/dam/oliver-wyman/v2/careers/profiles/scottbk-profile-460x460.jpg"),
  new Chat_Data_Model(
      name: "George",
      message: " Hi... cheerful confined.... ",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2015/06/22/08/40/child-817373__340.jpg"),
  new Chat_Data_Model(
      name: "	Ava",
      message: " Hi... Situation admitting promotion...",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2016/11/29/03/36/beautiful-1867093__340.jpg"),
  new Chat_Data_Model(
      name: "Grace",
      message: " Hi... Whatsapp How are you ?",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2015/11/26/00/14/fashion-1063100__340.jpg"),
  new Chat_Data_Model(
      name: "Leo",
      message: " Hi... Total state as merit court green",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2016/11/29/02/28/attractive-1866858__340.jpg"),
  new Chat_Data_Model(
      name: "Jack",
      message: " Hi... As he instantly on discovery concluded to.",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2017/06/26/02/47/people-2442565__340.jpg"),
  new Chat_Data_Model(
      name: "Amelia",
      message: " Hi... Face do with in need of wife paid that be. ",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2018/01/24/19/49/people-3104635__340.jpg"),
  new Chat_Data_Model(
      name: "Sophia",
      message: " Hi...  Given mrs she first china",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2017/11/23/07/47/babe-2972221__340.jpg"),
  new Chat_Data_Model(
      name: "Harry",
      message: " Hi... Is post each that just leaf no....",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2018/02/21/15/06/woman-3170568__340.jpg"),
  new Chat_Data_Model(
      name: "Isla",
      message: " Hi...Surprise not wandered speedily ...",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2016/01/19/18/04/man-1150058__340.jpg"),
  new Chat_Data_Model(
      name: "Emily",
      message: " Hi...Extended kindness trifling remember ...",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2015/07/31/15/01/man-869215__340.jpg"),
  new Chat_Data_Model(
      name: "Mia",
      message: " Hi...She exposed painted fifteen are noisier....",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2016/03/24/09/10/men-1276384_960_720.jpg"),
  new Chat_Data_Model(
      name: "Poppy",
      message: " Hi... Admiration we surrounded possession ...",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2015/07/14/06/06/homeless-844208__340.jpg"),
  new Chat_Data_Model(
      name: "Alfie",
      message: " Hi... Entire any had depend and figure winter.",
      time: "04:30 AM",
      profilepic:
          "https://cdn.pixabay.com/photo/2017/08/12/18/31/male-2634974__340.jpg"),
];

Step 3 : Create a new Package/ Directory for TabPages

Right click on lib > New >Package name the package as “TabPages”  or anything it’s left to you.

package directory creation in flutter project
package directory creation in flutter project

Create 4 dart files under TabPages folder

How to Create dart file in android Studio?

Right Click Tabpages > New > dart

like that create 4 dart file.

  1. Callspage.dart
  2. CameraPage.dart
  3. Chatpage.dart
  4. Statuspage.dart
Tabpages for whats app clone tabs

Then Just Copy below dart page code in those dart file you have created just now

1. CallsPage.dart

import 'package:flutter/material.dart';

class CallsPage extends StatefulWidget {
  @override
  _CallsPageState createState() => _CallsPageState();
}

class _CallsPageState extends State<CallsPage> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("Call Page"),
    );
  }
}

2. CameraPage.dart

import 'package:flutter/material.dart';

class CameraPage extends StatefulWidget {
  @override
  _CameraPageState createState() => _CameraPageState();
}

class _CameraPageState extends State<CameraPage> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("Camera Page"),
    );
  }
}

3. Statuspage.dart

import 'package:flutter/material.dart';

class Statuspage extends StatefulWidget {
  @override
  _StatuspageState createState() => _StatuspageState();
}

class _StatuspageState extends State<Statuspage> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("Status Page"),
    );
  }
}

4. ChatsPage.dart

import 'package:flutter/material.dart';
import 'package:whatsappcloneflutter/Data_Model/Chat_Data_Model.dart';

class ChatPage extends StatefulWidget {
  @override
  _ChatPageState createState() => _ChatPageState();
}

class _ChatPageState extends State<ChatPage> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: dummyData.length,
      itemBuilder: (context, index) => Column(
        children: <Widget>[
          Divider(
            height: 10.0,
          ),
          ListTile(
            leading: CircleAvatar(
              radius: 20,
              foregroundColor: Theme.of(context).primaryColor,
              backgroundColor: Colors.grey,
              backgroundImage: NetworkImage(dummyData[index].profilepic),
            ),
            title: new Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  dummyData[index].name,
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  dummyData[index].time,
                  style: TextStyle(fontSize: 14.0),
                ),
              ],
            ),
            subtitle: Container(
              padding: const EdgeInsets.only(top: 5.0),
              child: Text(
                dummyData[index].message,
                style: TextStyle(color: Colors.grey, fontSize: 16.0),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Step 4 : At Last open main.dart file and paste the below code

main.dart

import 'package:flutter/material.dart';
//importing all the whatsapp clone tab pages 
import 'package:whatsappcloneflutter/TabPages/CallsPage.dart';
import 'package:whatsappcloneflutter/TabPages/CameraPage.dart';
import 'package:whatsappcloneflutter/TabPages/ChatPage.dart';
import 'package:whatsappcloneflutter/TabPages/Statuspage.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'WhatApp Clone Example',
      theme: ThemeData(
          primaryColor: Color(0XFF075E54),
          accentColor: Color(0XFF25D366) // green color for whatapp clone theme
          ),
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // total tab we are creating is 4 so : length is 4 : initialIndex is set to position 1
    _tabController = new TabController(length: 4, vsync: this, initialIndex: 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("WhatsApp Clone app UI"),
        elevation: 0.5,
        bottom: TabBar(
          controller: _tabController,
          indicatorColor: Colors.white,
          tabs: <Widget>[
            // here we are creating 4 Tabs
            Tab(icon: Icon(Icons.camera_alt)),
            Tab(
              text: "CHATS",
            ),
            Tab(
              text: "STATUS",
            ),
            Tab(text: "CALLS")
          ],
        ),
        //we need 2 menu icons on app bar : search and more setting
        actions: <Widget>[
          Icon(Icons.search),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 7),
          ),
          Icon(Icons.more_vert)
        ],
      ),
      body: TabBarView(
        //this will work similar to fragment in android app
        controller: _tabController,
        //loading 4 pages in tabs
        children: <Widget>[CameraPage(), ChatPage(), Statuspage(), CallsPage()],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          print("Floating Button Clicked");
        },
        backgroundColor: Theme.of(context).accentColor,
        child: Icon(
          Icons.message,
          color: Colors.white,
        ),
      ),
    );
  }
}

There you go your Flutter app is now ready to show  WhatsApp UI Design Clone.

NOTE : Here we have just Created a Dummy Data for Chat Page, In upcoming updates we will create update data for status page and calls pages too.

If you face any kind of problem feel free to comment below. I will Replay in less then 12 hours Sure.

Thank you

Recommended Post

flutter instagram ui clone

How to convert website to android app?

3
How to Convert Website into Android App in android studio using WebView Android Studio

Hi Guys, Welcome to Proto Coders Point, In this Android Tutorial we will create an App that convert a website into an app.

For this we gonna use webview to display our website

What is Webview in android?

In android a webview is a component of android Operating system(OS) that allows our application to load and display any website into an application.

This tutorial will be short and simple to understand so let’s begin implementation to display website straight into our android applicaton.

How to Convert Website into Android App ? Follow the Steps.

you can even learn this from below video

Step 1: Create a new Android Project or open Existing Project.

OffCourse you need to create a new android project.

Go to File > New > New Project  name the project as “Loading Website android”  or as per your choice.

Step 2 : Add Internet Permission

Open AndroidManifest.xml file and add the <user-permission> INTERNET as we gonna load a URL into our android application we do need INTERNET PERMISSION to be set.

paste below inside <manifest> tag in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

Step 3 : Add webview in activitymain.xml file

Now open activitymain.xml file, Here you need to add a widget WebView  here we will load the URL and display the website.

paste the below xml Code

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"
    tools:context=".MainActivity">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

Step 4: Java android Code to loadURL in webview

Then, Now open MainActivity.xml  and add the java code

package com.protocoderspoint.webviewexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //find the view
        webView = (WebView)findViewById(R.id.webview);
        // to load all the web page in app itself use this
        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl("https://protocoderspoint.com/");

        WebSettings webSettings =webView.getSettings();

        //if your website is using any javascript that needs to load some script then you need to enable javascript in android application
        webSettings.setJavaScriptEnabled(true);

    }

    @Override
    public void onBackPressed() {
        // if any previous webpage exist then onback pressed will take care of it

        if(webView.canGoBack())
        {
            webView.goBack();
        }else{

            //else it will exit the application
            super.onBackPressed();
        }

    }
}

 

If you are interested in Flutter Development then Check flutter tutorial to load website in app

 

How to create rating bar dialog in Flutter App – a smooth star rating flutter dialog

0
flutter smooth star rating dialog
flutter smooth star rating dialog

Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we will discuss & implement 2 different flutter plugin/library, that is been used to ask use to 5 star rating review in our flutter application.

I have found best rating plugin in flutter

  1. smooth star rating flutter 
  2. rating_dialog – flutter app rating dialog

Video Tutorial

1. Flutter Smooth Star rating ( library 1)

smooth star rating flutter plugin library

This library is the best library as it comes with a star rating with touch and even it enables to swipe rating to star review. It’s named as smooth star rating flutter because this library will detect this gesture you make on the flutter star rating icon to give the rating.

This are the feature of this library:

Change the default star icons with your desired Icons.

Give user to rate using half rate or full ( Eg : 2.5 rating or  4.5 rating )

swiping on icon will increment/decrement the rating bar star.

and many more feature.

To learn more visit official site here

  • Supports replacing default star icons with desired IconData
  • Supports half rate and full rate (1.0 or 0.5)
  • Swipe for incrementing/decrementing rate amount
  • Change star body and boundary colors independently
  • Control size of the star rating
  • Set your desired total Star count
  • Supports click-to-rate
  • Spacing between stars

Installation smooth  star rating 

Add dependencies

open pubspec.yaml and all the following dependencies line.

dependencies:
  smooth_star_rating: ^1.0.4+2   // add this line

Then, just click on package_get this will download all the required classes in your flutter project.

Import the package class file

Then, after adding  the library, you need to import the smooth_star_rating.dart  wherever you need to show star review rating bar.

import 'package:smooth_star_rating/smooth_star_rating.dart';

Snippet code of showing star rating widget

SmoothStarRating(
               rating: rating,
               size: 35,
               filledIconData: Icons.star,
               halfFilledIconData: Icons.star_half,
               defaultIconData: Icons.star_border,
               starCount: 5,
               allowHalfRating: false,
               spacing: 2.0,
               onRatingChanged: (value) {
                 setState(() {
                   rating = value;
                 });
               },
             ),

Different parameters you can use here:

allowHalfRating                 -   Whether to use whole number for rating(1.0  or 0.5)
onRatingChanged(int rating)     -   Rating changed callback
starCount                       -   The maximum amount of stars
rating                          -   The current value of rating
size                            -   The size of a single star
color                           -   The body color of star
borderColor                     -   The border color of star
spacing                         -   Spacing between stars(default is 0.0)
filledIconData                  -   Full Rated Icon
halfFilledIconData              -   Half Rated Icon
defaultIconData                 -   Default Rated Icon


2. Flutter Rating Dialog ( Library 2 )

This flutter rating dialog is awesome as it provide beautiful and customizable Rating star icon dialog package for flutter application development.

rating dialog futter library

Installation of Flutter rating dialog plugin

Adding depencencies

Open pubspec.yaml file and all the below raiting dialog depencencies

dependencies:
  rating_dialog: ^1.0.0   // add this line

Then, just click on package_get this will download all the required classes in your flutter project.

Import the package class file

Then, after adding  the library, you need to import the rating_dialog.dart  whereever you need to show rating dialog box.

import 'package:rating_dialog/rating_dialog.dart';

Snippet Code to show AlertDialogin flutter with rating dialog

void show() {
    showDialog(
        context: context,
        barrierDismissible: true, // set to false if you want to force a rating
        builder: (context) {
          return RatingDialog(
            icon: const Icon(
              Icons.star,
              size: 100,
              color: Colors.blue,
            ), // set your own image/icon widget
            title: "Flutter Rating Dialog",
            description: "Tap a star to give your rating.",
            submitButton: "SUBMIT",
            alternativeButton: "Contact us instead?", // optional
            positiveComment: "We are so happy to hear 😍", // optional
            negativeComment: "We're sad to hear 😭", // optional
            accentColor: Colors.blue, // optional
            onSubmitPressed: (int rating) {
              print("onSubmitPressed: rating = $rating");
              // TODO: open the app's page on Google Play / Apple App Store
            },
            onAlternativePressed: () {
              print("onAlternativePressed: do something");
              // TODO: maybe you want the user to contact you instead of rating a bad review
            },
          );
        });
  }

The above snippet code has a method show() which have showDialog() widget that will return/display RatingDialog() which is a class of this library.

RatingDialog() widget have various parameters or we can say features.

icon : when you can display your flutter app logo

title: basically to title text

description :  text to ask user for there valuable star reviews.

submitButton : will show a simple button for submission of the review.

alternativeButton : you may use this button to navigate user to URL of your company website to know more.

positiveComment : if you select more the 3 star rating then you can show a positive message to user.

negativeComment: if you select 3 or less star rating then you can show different message to user.

onSubmitPressed(){} : what action to be performed when used click of submit review button

onAlternativePressed(){} : where the used should be navigated when user click on more info  button.

Complete Source Code with above 2 rating bar dialog example in flutter

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:smooth_star_rating/smooth_star_rating.dart';
import 'package:rating_dialog/rating_dialog.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,
      ),
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage> {
  double rating = 4.0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("App Rating stars")),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                "Library First :  'Smooth Star Rating' ",
                style: TextStyle(fontSize: 20),
              ),
              SizedBox(
                height: 10,
              ),
              SmoothStarRating(
                rating: rating,
                size: 35,
                filledIconData: Icons.star,
                halfFilledIconData: Icons.star_half,
                defaultIconData: Icons.star_border,
                starCount: 5,
                allowHalfRating: true,
                spacing: 2.0,
                onRatingChanged: (value) {
                  setState(() {
                    rating = value;
                    print(rating);
                  });
                },
              ),
              Text(
                "You have Selected : $rating Star",
                style: TextStyle(fontSize: 15),
              ),
              SizedBox(
                height: 15,
              ),
              Text(
                "Library Second:  'Rating_Dialog ' ",
                style: TextStyle(fontSize: 20, color: Colors.deepOrange),
              ),
              RaisedButton(
                onPressed: () {
                  show();
                },
                child: Text("Open Flutter Rating Dialog Box"),
              )
            ],
          ),
        ));
  }

  void show() {
    showDialog(
        context: context,
        barrierDismissible: true, // set to false if you want to force a rating
        builder: (context) {
          return RatingDialog(
            icon: const Icon(
              Icons.star,
              size: 100,
              color: Colors.blue,
            ), // set your own image/icon widget
            title: "Flutter Rating Dialog",
            description: "Tap a star to give your rating.",
            submitButton: "SUBMIT",
            alternativeButton: "Contact us instead?", // optional
            positiveComment: "We are so happy to hear 😍", // optional
            negativeComment: "We're sad to hear 😭", // optional
            accentColor: Colors.blue, // optional
            onSubmitPressed: (int rating) {
              print("onSubmitPressed: rating = $rating");
              // TODO: open the app's page on Google Play / Apple App Store
            },
            onAlternativePressed: () {
              print("onAlternativePressed: do something");
              // TODO: maybe you want the user to contact you instead of rating a bad review
            },
          );
        });
  }
}
flutter smooth rating dialog plugin

Recommended Articles

android alert dialog example

Alert dialog in flutter

bottom popup android – bottom sheet dialog fragment