Home Blog Page 78

flutter bottom navigation bar example 4 pages – Convex Bottom Bar Library

1
convex flutter bottom navigation bar
convex flutter bottom navigation bar

Hi Guys, Welcome to Proto Coders Point, In this Flutter tutorial we gonna add Bottom navigation bar to our flutter application, So to achieve this we will make use of Flutter Convex Bottom bar library.

Official Convex Bottom bar library page https://pub.dev/packages/convex_bottom_bar Learn more about it.

VIDEO TUTORIAL OF FLUTTER BOTTOM NAVIGATION BAR

if you don’t know how Convex Bottom navigation bar  look like in Flutter, Check out below screenshot of the application output.

flutter convex navigation bar example

Instead, you’re switching out a over all group of content within a single page to give the appearance that the page is changing.Here is a illustration to visually describe what we’re doing. Not that the overall “scaffolding”, as Flutter calls it, stays the same and the contents within the page change.

flutter-bottom-navigation-bar canvex example
Bottom navigation bar with 3 different page switch

Ok so now let’s begin developing flutter application with Convex Bottom bar library

Flutter Bottom Navigation Bar Example

Step 1: Create a new Flutter Project

offcourse you need to create a new Flutter Project, In this tutorial i m making use of Android Studio as my IDE to develop Flutter Projects.

File > New > New Flutter Project

Give a suitable name to your Flutter project and and hit next next finish.

Once the Flutter Project is ready, Flutter project will be built with some default code, just remove all those default code and copy paste below code for a quick start.

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(title: 'Flutter Convex Bottom Bar'),
    );
  }
}

class HomeMainPage extends StatefulWidget {
  @override
  _HomeMainPageState createState() => _HomeMainPageState();
}

class _HomeMainPageState extends State<HomeMainPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("This is Main Page "),
    );
  }
}

Step 2: Add the required dependencies library

As i said at the beginning, i am going to make use of external library to add Bottom material navigation bar in our flutter project.

to add the dependencies, navigate/open pubspec.yaml file and add the following dependencies

dependencies:
  flutter:
    sdk: flutter
  convex_bottom_bar:  #add this line

after adding, just hit that pub get text on top at appears when any change is been done in pubspec.yaml file.

what this will do is, it will fetch all the required library and store into your flutter project as external library.

Step 3: Import the Convex library when required

As you have added the Bottom bar convex library dependencies now you can easily make use of that library just be importing it wherever required.

import 'package:convex_bottom_bar/convex_bottom_bar.dart';

Step 4: How to use Convex bottom navigation bar  (Snippet code)

bottomNavigationBar: ConvexAppBar(

          items: [
            TabItem(icon: Icons.home, title: 'Home'),
            TabItem(icon: Icons.favorite, title: 'Favorites'),
            TabItem(icon: Icons.search, title: 'Search'),
            TabItem(icon: Icons.person, title: 'Profile'),
          ],
          initialActiveIndex: 0,//optional, default as 0
          onTap: (int i ){
           //will print index value of which item is been clicked 

            print("index $i");
          },
        ),

brief description of above Convex App Bar snippet code

as you can see i have added 4 items with some Icons and title to each items.

initialActiveIndex: its is the tab that you want to make active page when the app is been opened for first time.

onTap: will trigger which TabItem index is been pressed, By making use of this index value we can change the page.

Step 5: Create 4 pages

As we are building the app with bottom navigation bar, we required 4 more page that will be displayed in main.dart page body tag.

now create 4 dart file in lib directory of  your flutter project.

Right Click on lib directory > New >Dart File

Home.dart

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

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(child: Text("Home Page",style: TextStyle(fontSize: 20),))
        ],
      ),
    );
  }
}

Favorites.dart

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

class Fav extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(child: Text("Favorites Page",style: TextStyle(fontSize: 20),))
        ],
      ),
    );
  }
}

Search.dart

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

class Search extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(child: Text("Search Page",style: TextStyle(fontSize: 20),))
        ],
      ),
    );
  }
}

Profile.dart

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

class Profile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Center(child: Text("Profile Page",style: TextStyle(fontSize: 20),))
        ],
      ),
    );
  }
}

then now, we have created 4 page, that will be displayed when items from bottom navigation bar is been clicked.

Step 6: Final Complete Flutter Code to Display Bottom Navigation bar with pages

Explanation of what going on the below code

i have declared 2 variable

selectedPage is of type integer value with default value as 0

and pageOptions with 4 pages stored in a form arrays.

int selectedPage = 0;
  final _pageOptions = [Home(),  Fav(),Search(), Profile()];

here intial selected page index is 0 so Home() page will be shown when the app get launched first.

body: _pageOptions[selectedPage],

and in bottomNavigationBar tab: we have

bottomNavigationBar: ConvexAppBar(

  items: [
    TabItem(icon: Icons.home, title: 'Home'),
    TabItem(icon: Icons.favorite, title: 'Favorites'),
    TabItem(icon: Icons.search, title: 'Search'),
    TabItem(icon: Icons.person, title: 'Profile'),
  ],
  initialActiveIndex: selectedPage,//optional, default as 0
  onTap: (int index ){
    setState(() {
      selectedPage = index;
    });
  },
),

Here we have 4 tabs in Bottom bar Home, Favorites, Search, Profile, and initialActiveIndex is set to 0 that is selectedPage, and when any Tab is been Pressed onTap will get Triggred with the index value Tab that been selected and selectedPage will get changed with the index value , and hence selected Index page will be get displayed in body tag of main.dart page.

Complete  flutter code

import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'Home.dart';
import 'Fav.dart';
import 'Search.dart';
import 'Profile.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(title: 'Flutter Convex Bottom Bar'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  int selectedPage = 0;
  final _pageOptions = [Home(),  Fav(),Search(), Profile()];


  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),
      body: _pageOptions[selectedPage],
        bottomNavigationBar: ConvexAppBar(

          items: [
            TabItem(icon: Icons.home, title: 'Home'),
            TabItem(icon: Icons.favorite, title: 'Favorites'),
            TabItem(icon: Icons.search, title: 'Search'),
            TabItem(icon: Icons.person, title: 'Profile'),
          ],
          initialActiveIndex: 0,//optional, default as 0
          onTap: (int i ){
            setState(() {
              selectedPage = i;
            });
          },
        ),// This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Conclusion

In this above Flutter tutorial we have learnt how to add Botton Navigation bar in our flutter project

Related Flutter tutorial articles

bottom navigation bar flutter

Flutter Bottom Navigation Bar with Fancy Animation effect

Flutter UI/UX Animated Curved Navigation Bar Library

Flutter BLoC Pattern Tutorial – Inc & Dec Example

1
Flutter BLoC Pattern Tutorial - Inc & Dec Example
Flutter BLoC Pattern Tutorial - Inc & Dec Example

Hi Guys, Welcome to Proto Coders Point, In this Flutter Tutorial we gonna Learn basic of Flutter BLoC Pattern, Basically we will build a simple app that can perform Increment & Decrement operations.

FINAL RESULT

Bloc pattern inc and dec app

What is a Bloc?

A BLoC we can simply understand with the help of below Diagram.

simple way to understand Flutter bloc pattern with example

Business logic Component is basically a Box where Events cames from one side & the State comes out with the required data from other side.

Check out the tutorial atricle on Introduction of Flutter Bloc pattern

https://protocoderspoint.com/introduction-to-flutter-bloc-pattern-tutorial/ 

Flutter is really an awesome framework because it allows fully freedom to the app developer in how to manage the state, If i say BLoC (Business Logic Component) pattern is the prefect tool that fits for Flutter application and that is the reason i am here with Flutter BLoC pattern tutorial.

Flutter BLoC Pattern Tutorial – Inc & Dec Example

So Basically  in our Flutter Bloc pattern example, there are 2 kinds of events that will be performed by the used i.e 1. Increment Event 2. Decrement Event.

Video Tutorial on Flutter BLoC Pattern

 

Step 1: Create a dart file (Event_Counter)

Now, Create a dart file inside lib folder of your flutter project & name it as

This File will handle event.

Event_Counter.dart

abstract class EventCounter{}

//abstract class to find out which Event was occurred

class IncrementEvent extends EventCounter{}

class DecrementEvent extends EventCounter{}

Step 2: Create a Flutter BLoC Class

then, Now Create a Flutter BLoC Class dart file under lib directory and name it as BlocCounter.dart

import 'dart:async';
import 'EventCounter.dart';

// async enable

class Bloc_Counter{
  int _counter = 0;

  //StreamCountroller handle input and output
  final _counterStateController = StreamController<int>();

  // Sink in Flutter can be easily stated, In Simple Words Sink = Import
  StreamSink<int> get _inCounter =>_counterStateController.sink;

  // Stream in Flutter can be easily stated, In Simple Words Stream = Output
  Stream<int> get counter =>_counterStateController.stream;

  //event controller to trigger which event has occurred
  final _counterEventController = StreamController<EventCounter>();

  Sink<EventCounter> get counterEventSink =>_counterEventController.sink;

  Bloc_Counter(){
    _counterEventController.stream.listen((_mapEventtoState));
  }

  void _mapEventtoState(EventCounter event){
    // depending on event either increment or decrement the counter variable
    if(event is IncrementEvent)
      _counter++;
    else
      _counter--;

    _inCounter.add(_counter);

  }

  // Dispose the Controller, Very important step, Otherwise you may get memory leak
  void dispose(){
    _counterStateController.close();
    _counterEventController.close();
  }
}

Brief information of what is going on the above Flutter Bloc pattern code.

async allows us to use Flutter Feature like StreamController, Stream, Future and Sink.

Sink in Flutter can be easily stated, In Simple Words Sink = Import.

Stream in Flutter can be easily stated, In Simple Words Stream = Output.

Event controller to trigger which event has occurred

and every Controller must be disposed when application is not in use, otherwise it may lead to memory leak.

Step 3: UI Design

Then, open main.dart file and copy paste below lines of code

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc_example/Bloc_Counter.dart';
import 'package:flutter_bloc_example/EventCounter.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.blue,

        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage> {
  final _bloc = Bloc_Counter();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter Bloc Example"),
      ),
      body: Center(
        child: StreamBuilder(
          stream: _bloc.counter,
          initialData: 0,
          builder: (BuildContext context,AsyncSnapshot<int> snapshot){
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Image.network("https://raw.githubusercontent.com/felangel/bloc/master/docs/assets/flutter_bloc_logo_full.png",width: 250,height: 200,),
               Text("Flutter Bloc Example", style: TextStyle(fontStyle: FontStyle.italic,fontSize: 25),),
                Text("Press Below Button "),
                Text(
                  '${snapshot.data}',
                  style: TextStyle(fontSize: 30)
                ),
              ],
            );
          },
        ),
      ),
        floatingActionButton: Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            FloatingActionButton(
              child: Icon(Icons.add),
              backgroundColor: Colors.green,
              onPressed: (){
                print("Increment");
                //class bloc class by passing IncrementEvent
                _bloc.counterEventSink.add(IncrementEvent());
              },
            ),
            SizedBox(
              width: 20,
            ),
            FloatingActionButton(
              child: Icon(Icons.remove),
              backgroundColor: Colors.red,
              onPressed: (){
                print("Decrement");
                //class bloc class by passing DecrementEvent
                _bloc.counterEventSink.add(DecrementEvent());
              },
            )
          ],
        ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    //dispose all the controller
    _bloc.dispose();
  }
}


Thus, your Flutter Application is ready with Flutter Bloc Feature.

Guys, if you have any confusion just check out my Project Structure below.

flutter bloc project structure example

Conclusion

In this article we learnt How to Build and Flutter App, that can perform Increment and Decrement operation by using Flutter Business Logic Component to perform the event and change the Flutter application UI state as per .

Introduction to Flutter BLoC Pattern | Flutter Bloc tutorial with Example

1
Flutter BLoC Pattern tutorial with example
Flutter BLoC Pattern tutorial with example

Hi Guys, Welcome to Proto Coders Point, In this Flutter bloc Tutorial we gonna learn about what is BLoC patterns in Flutter, and how to Implement the Flutter Business Logic Component Flutter bloc example.

What is Flutter BLoC?

In order to learn or understand anything about BLoC, you need to have some basic knowledge about these 4 terms in Flutter Development.

  1. State
  2. Event
  3. Stream
  4. Sink.

State: A State in the flutter app is nothing but the data your application is currently been showing. As you guys know that Flutter is a reactive framework as data changed, Application UI also gets change.

Event: An Event is an action that is detected by the application, Typically, it’s a user action like clicking on a button and some action is be performed.

Stream: A Stream can be considered as a medium through which data is transferred. Easily understanding of Stream can be assumed like a pipeline from where the water is been supplied to other ends, How water travel through pipeline like the same way data is transferred through the stream.

flutter bloc stream diagram

There comes a point where we consume or receive data that is been flowing through the stream, This is where we can call Sink

Sink: A Sink can e considered as the point where you receive or consume data from a stream.

So now you know basics of these 4 terms, now you can easily understand what is flutter BLoC.

Flutter Bloc Pattern

3 different component of Flutter BLoC Pattern

  • UI
  • BLoC
  • Data Provider

component of flutter BLoC

Here UI can interact with bloc & bloc can also do the same.

The Bloc provider can interact with the data provider for data.

What is BLoC Stands For?

A BLoC stands for Business Logical Component, A Flutter BLoC contents all the Business logic of a Application.

What is Data Provider in BLoC Pattern?

A Data Provider can be considered as your back-end i.e your database where all the users data is been stared.

How Flutter BLoC Works?

When an application is built using the Flutter BLoc pattern, whenever any data change is found in the data provider, BLoC (Business Logic Component) applies business logic to the current state & it re-creates the new state to the UI & when UI receive the new state it re-render itself to show the latest version of UI with new data that is been received from the data provider.

Let’s Understand Flutter Bloc with an Application Example

Flutter BLoC Pattern Example
Flutter BLoC Pattern Example

Flutter BLoC Pattern Tutorial Example

Step 1: Create a new Flutter project

In my case, I am making use of the android studio as my IDE to develop the Flutter project

Create new Project File > New > New Flutter Project

Give a name to your project as “Flutter Bloc Load image Example” or anything as per your choice.

Step 2: Add Required Dependencies

Then, Open pubspec.yaml file and add below 2 dependencies

dependencies:
  flutter:
    sdk: flutter
  flutter_bloc: ^6.0.1  #this
  bloc: ^6.0.1          #this

after adding this 2 dependencies now click on  pub get text, What this will do is download all the required packages into your flutter project external library.

Step 3: Create a new dart file

Then, once you have added bloc dependencies, now create a new dart file under the lib directory and name it as “BlocImage.dart” 

and then Copy below lines of BlocImage Code that will simply return the URL of an image.

import 'package:bloc/bloc.dart';

enum ImageEvent{getImage}

class BlocImage extends Bloc<ImageEvent,String>
{
  BlocImage(String initialState) : super('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/1024px-No_image_available.svg.png');

  @override
  Stream<String> mapEventToState(ImageEvent event)  async*{
    // TODO: implement mapEventToState
    yield 'https://protocoderspoint.com/wp-content/uploads/2019/10/protocoderspoint-rectangle-round-.png';
  }

}

Note: return, returns the values and also terminates the function, where a yield, returns the value but does not terminate the function.

In the above Bloc code I have set initialState to an image URL that has Not to Image Message, and when the user clicks on Button event mapEventToState gets trigged and original image will get displayed on the screen.

Step 4: main.dart file

Copy-paste the below code in main.dart file

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_example/BlocImage.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: Scaffold(
        body: BlocProvider(
          create: (BuildContext context)=> BlocImage("0"),
          child: MyHomePage(),
        ),
      ),
    );
  }
}
class MyHomePage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    final _blocimage = BlocProvider.of<BlocImage>(context);
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Image.network("https://raw.githubusercontent.com/felangel/bloc/master/docs/assets/flutter_bloc_logo_full.png",width: 250,height: 200,),
          Text("Flutter Bloc Example", style: TextStyle(fontStyle: FontStyle.italic,fontSize: 30),),

          BlocBuilder<BlocImage,String>(
            builder: (BuildContext context,String urlstate){
              return Image.network(urlstate,width: 200,height: 200,);
            },
          ),
          ButtonBar(
            alignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                child: Text("Get  Image"),
                color: Colors.blue[700],
                onPressed: (){
                  _blocimage.add(ImageEvent.getImage);
                },
              ),
            ],
          )
        ],
      ),
    );
  }
}



So In Above lines of code i have wrapped MyHomePage widget class in BloCprovider, what the BLocProvider will do is, it will pass the BlocImage instance to its child MyHomePage.

So to refer BlocImage in your MyHomePage i have created a final variable as you may see in above complete or below snippet code.

final _blocimage = BlocProvider.of<BlocImage>(context);

on Button Click Event new data will be fetched from the Flutter BLoC pattern

RaisedButton( child: Text("Get Image"), color: Colors.blue[700], onPressed: (){ _blocimage.add(ImageEvent.getImage); }, ),

Which widget should get re-rendered on data change can be done as below

BlocBuilder<BlocImage,String>( builder: (BuildContext context,String urlstate){ return Image.network(urlstate,width: 200,height: 200,); }, ),

FINAL FLUTTER BLOC EXAMPLE OUTPUT TO LOAD IMAGE AFTER BUTTON CLICK EVENT

flutter bloc tutorial example gif

Sorry, Here Click is not visible, So when I click on the Get Image button the Image is getting loaded from the URL I have provided.

How to Generate Flutter App icons – Flutter Launcher Icons Change

2
Easy way to change App ICON

Hi Guys, Welcome to Proto Coders Point, In the Flutter tutorial we will generate an app icon for your flutter project Launcher icon.

To do so we gonna make use of a flutter library called Flutter Launcher Icons Generator – A True Icon.

Official Site Link: https://pub.dev/packages/flutter_launcher_icons

Brief about Flutter Launcher Icons

Flutter Launcher icons are been built so that developers can easily use them to update their flutter app icon very easily.

This Library is Fully Flexiable, as it allows us to choose for which platform you want change/update the launcher icon, and if you want to keep backup of old icon you can do it by using this library.

So let’s Begin the Process,

Note: I am using Android Studio for developing the Flutter Application and demonstrate how to generate flutter app icon.

Video Tutorial

Step 1: Create a new Flutter Project

ha ha ha, Offcourse you need a flutter project, In Android-Studio or any of your IDE create a new Flutter Project.

File => New => New Flutter Project

Give a name to your flutter project and continue.

Step 2: Add Launcher Icon Library Dependencies

Then, open pubspec.yaml file ( found in your project ) and add the following dependencies line.

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.7.3"   #this line

After that add flutter_icons with image path that you want to make as your application launcher icons.

flutter_icons:
  android: true
  ios: true
  image_path: "images/icons/protocoderpoint.png" #

Here

android: true: by setting it to true launcher icon will be created for android and ios devices.

image_path: is the path of the image that you want to make or generate app icon as your application 1 launcher icon.

Here is an Example of how my pubspec.yaml file looks after adding dev_dependencies and flutter_icons.

flutter launcher icon add dev dependencies

Step 3: Create an image directory path and add image assets

Now, you need to add the image that you want to generate app icon, for that you need to create image directory and paste a image in it.

creating new assets folder in flutter project to store images

Right click on your project => New > Directory then Create a folder by name image.

as you can see in above screenshot i have protocoderspoint.png image inside image/icons/protocoderspoint.png

Final Step 4: Run the Command to generate app icons

In your IDE there might be terminal/command prompt.

Open it and run 2 commands as given below.

flutter pub get   #get all the new/latest packaged from dependencies

flutter pub run flutter_launcher_icons:main  # this command generate 0 launcher icon for you in your project

The above command will create different size mipmap image for android and assets app Icon  for iOS devices.

flutter launcher icon creating using library

Final Result – true icon

once your run the above command the app launcher image will get automatically created as shown below.

icon created for your application launcher icon flutter

Flutter vs React Native 2021 – What to learn for 2021?

1
Flutter vs reach native 2020 - which to choose in 2021

Hi Guys, Welcome to Proto Coders Point, In this Blog Post we will discuss on Flutter vs React Native 2020, year is almost at the end so, which is best flutter or react native in 2021 for your development career.

Introduction to Flutter and React Native

What is Flutter? Who created Flutter?

A Flutter is a development framework/Kit, which is created by Google and it’s team. By using flutter as a development kit you can develop applications for Android, iOS and Web that too from a single codebase (Code once and build installation setup for various platform)

Hello, World program in Flutter looks like this:

import 'package:flutter/material.dart';

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

class HelloWorldApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    //MaterialApp acts as a wrapper to the app and 
    //provides many features like title,home,theme etc   
    return MaterialApp(
      title: 'Hello World App',

      //Scaffold acts as a binder that binds the appBar,
      //bottom nav bar and other UI components at their places     
      home: Scaffold(

          //AppBar() widget automatically creates a material app bar
        appBar: AppBar(
          title: Text('Hello World App'),
        ),

        //Center widget aligns the child in center
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

Check out this tutorial how to install flutter and build your first Hello World app in flutter

What is React Native? Who created Flutter?

React Native is one for the famous framework used to develop applications for Android, iOS, web and more, React Native helps developer to use react along with native platform capabilities.

React Native also allows developers to write native code in languages such as Java for Android and Objective-C or Swift for iOS which make it even more flexible.

Hello, World program in React Native looks like this:

import React, { Component } from 'react';
import { Text, View } from 'react-native';

export default class HelloWorldApp extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
        <Text>Hello, world!</Text>
      </View>
    );
  }
}

Pros and Cons of Flutter

Pros :

  • Easy to Learn and user friendly to designs user interface
  • it has a number of “ready to use” widgets in which most of the widgets help in material design UI concepts.
  • since it supports Hot Reload it makes testing faster and it provides fast coding.

Cons:

  • The widgets used in flutter adaptive so they need to be configured manually so that they can adapt.
  • Packages are fewer as that compared with the react native.
  • It becomes a bit harder to pickup with dart.
  • community support is less as flutter dart is new in market.

If you are good in beginner in flutter and looking job to learn more and get experience then here are some Flutter Interview Question and Answer that may be asked to you in interview round

Pros and cons of React Native

Pros

  • In react native the widgets avaliable are  adaptive automatically.
  • It can be easily understandable if one is familiar with javascript.
  • there are more number of packages avaliable here.
  • Strong community support as it been 5 year being in market.

Cons:

  • Less smooth navigation.
  • Lack of custom modules.
  • Facebook have many team and condition while using react native.

Difference between Flutter and React Native

 FlutterReact Native
Brief aboutA portable UI toolkit for building natively-compiled apps across mobile, web, and desktop* from a single codebaseA framework for building native applications using React
Release DateDecember 2018March 2015
Created byGoogleFacebook
Programming language usedDartJavaScript
open source?YESYES
Hot Reload Support?YESYES
Tops App developed using this FrameworkXianyu app by Alibaba, Hamilton app for Hamilton Musical, Google Ads appInstagram, Facebook, Facebook Ads, Skype, Tesla
Competitive advantageLooks Great and Speed UI designing thanks to rich widgets.

 

Flutter is growing rapidly and the community is also growing faster.

The support team for Flutter is getting stronger and Flutter comes with Excellent documentation work, which makes development easily.

Difficult to beat time-to-market length

It’s been Stability in market from last 5 years. And is getting great success.

 

Easy to learn technology as plenty of online tutorial are available.

React Native come with plenty of libraries and will make development much faster and easy to develop.

Code can be easily be re-used frm both web app and desktop application.

Recommended Article

Different between react and angular

Learn Angular – Build first web app using angular

Flutter vs React native

7 best tools for react development

How to use bootstrap in React

How to create custom hooks in react

Invisible Cloak From Harry Potter using python opencv

0

Hi Guys , Welcome to proto coders point, In this python tutorial we will implement invisible cloak from harry potter using python opencv library.

what are python libraries to use invisible cloak?

What is numpy?

This is python libraries where we are using for arrays perpose in our project.

what is opencv?

In this library we are using opencv to capture the video.

What is Time?

so we are using time to capture the video in that time.

Step 1 :Create new python project 

First we have to create a new python project to work on this invisible cloak.

File > New Project

Step 2 :Create a new python file to handle invisible cloak harry poter.

You need to create a new python file where you can write python code.

 Right click on Project > New > Python File

i have created a new python file with name as ” invisibility cloakusing pycharm IDE.

Step 3 : Add library in your python project.

How to install the numpy , opencv-python , time  module ?

File > Setting > Project Interpretor > Click on ” + ” >  Search for “numpy,python-opencv” then select the package and then click on install package button.

step 4 : Open the python file “invisible”

import cv2
import numpy as np
import time
out_name = "output_shri.avi"
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('shri.mp4' , fourcc, 20.0, (640,480))
time.sleep(2)
background = 0#capturing background
for i in range(30):
    ret, background = cap.read()#capturing image
while(cap.isOpened()):
    ret, img = cap.read()
    
    if not ret:
        break
        
    hsv=cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    lower_red = np.array([0,120,70])
    upper_red = np.array([10,255,255])
    mask1 = cv2.inRange(hsv , lower_red , upper_red)
    
    lower_red = np.array([170,120,70])
    upper_red = np.array([180,255,255])
    mask2 = cv2.inRange(hsv , lower_red , upper_red)
    
    mask1 = mask1 + mask2 #OR
    mask1=cv2.morphologyEx(mask1, cv2.MORPH_OPEN ,np.ones((3,3) , np.uint8) , iterations=2)
        
    mask2=cv2.morphologyEx(mask1, cv2.MORPH_DILATE ,np.ones((3,3) , np.uint8) , iterations=1)
        
    mask2 = cv2.bitwise_not(mask1)
    
    res1 = cv2.bitwise_and(background, background, mask=mask1)
    res2 = cv2.bitwise_and(img, img, mask=mask2)
    
    final_output = cv2.addWeighted(res1 , 1, res2 , 1, 0)
    
    cv2.imshow('Harry' , final_output)
    k=cv2.waitKey(10)
    if k==27:
        break
        
cap.release()
cv2.destroyAllWindows()

As we have installed the numpy ,opencv-python model in our project now you can just import the which ever library we have installed then we write the farther code.then we have  to capturing the video.after capturing video we have to give the camera to warm up.

Capturing the background in range of 60 .you should have video that have some seconds to dedicated to background farm so that it cloud easily save the background  image.

Then we are reading from video.so we are convert the image -BGR to HSV as we focused on detection of red color. and then converting BGR to HSV for better detection or you can convert it to gray.

we have ranges should be carefully chosen the setting the lower and upper range for mask1.some setting the lower and upper range for mask2.then it replaced with some other code depending upon the color of your cloth.then refining the mask corresponding to the detected red color.then we are generating the final output  

1.5. Final Result