What is flutter and it’s advantage and disadvantage

What is flutter?

Flutter is a Google-developed open-source framework that supports dart language (means we have to code in dart language). By this framework, we can not only develop android and iOS apps but also desktop and web apps as well with the help of a single code base.

The only main thing in flutter is widgets because the entire UI is based on widgets. In this framework there are tons of widgets like(button, menu, text…) and one more thing in flutter you should know about widgets life cycle which is given below : 

  • Widgets Lifecycle
  •  Stateless widget:
  1. The state does not change over time.
  2. build function runs only once.
  • StateFul widget:
  1. Over time, a state can shift
  2. setState() triggers the build function.

initState():

->Called only once when the widget is created.

-> Subscribe to streams or any object that could change our widget data.

Build():

-> Builds the widget tree.

-> A build is triggered every time we use setState().

Dispose():

-> When the widget/state object is removed.

Flutter Framework’s benefits and drawbacks are mentioned below:

 Let’s explore the benefits of a flutter:

  1. If you are an app developer then somehow you are developing your Android app in a different language and for iOS in a different language. For maintaining the two apps of different platforms you have to code in two languages. So, it is time-consuming. So, that’s why Google developed framework which is known as flutter by which we can create not even android app and iOS through the same code base but also web apps and desktop apps as well.
  2. Performance of flutter developed apps is high.
  3. Fast and simple to use.
  4. It’s open-source. You don’t have to pay to use this language.

Every language has it’s drawbacks. So, flutter have also a few drawbacks. Below, some of these are given:

  1. There are few supports of a third-party library. We can’t use flutter for using more third parties like Android as of now.
  1. Apps size is quite high compared to native language apps.

For eg: Hello world app in android app is of size less than 1 MB and in flutter Hello, world app is of the size of approx 5 MB.

If you create the flutter project in your IDE then it will create a counter application by default and it looks like this :

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 Demo Home Page'),

    );

  }

}

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 _counter = 0;

  void _incrementCounter() {

    setState(() {

      _counter++;

    });

  }

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        title: Text(widget.title),

      ),

      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,

          children: <Widget>[

            Text(

              'You have pushed the button this many times:',

            ),

            Text(

              '$_counter',

              style: Theme.of(context).textTheme.headline4,

            ),

          ],

        ),

      ),

      floatingActionButton: FloatingActionButton(

        onPressed: _incrementCounter,

        tooltip: 'Increment',

        child: Icon(Icons.add),

      ), 

    );

  }

}

For more details about flutter development, you can follow this link: https://flutter.dev/docs

So, enjoy Flutter development. Happy coding 🙂

Leave a Reply