Monday, 15 June 2020

How to Create Navigation Drawer in Flutter

Navigation Drawers are one of the primary options of navigation, especially if you are using material design in your mobile app. In this blog post, let’s check how to create a navigation drawer in Flutter.

Basically, you can create a navigation drawer in three steps:

  • Add a drawer using a Scaffold widget.
  • Populate drawer items.
  • Define actions when drawer items are clicked.

You will have two drawer items in this Flutter tutorial, one is messages and the other is settings. I am creating two screens so that I can navigate to them when the drawer items are pressed. Following is the messages screen.

import 'package:flutter/material.dart'; 

class Messages extends StatelessWidget {
 @override
Widget build(BuildContext context) {
return Main();
}
} /// This is the stateless widget that the main application instantiates.
class Main extends StatelessWidget { @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Messages'),
),
body: Center(
child: Text('See your messages here!')
),
);
}
}



Following is the settings screen.

import 'package:flutter/material.dart';



class Settings extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Main();
  }
}

/// This is the stateless widget that the main application instantiates.
class Main extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Settings'),
      ),
      body: Center(
        child: Text('Configure your settings here!')
      ),
    );
  }
}

Now, let’s come to our focal point- navigation drawer. As I mentioned earlier, you must have a Scaffold widget to incorporate the drawer. We use ListView as the child of the drawer so that we can easily scroll through when there are so many drawer items.

DrawerHeader widget is used to define the header content of the drawer whereas ListTile is used to create drawer items. We also defined routes so that we can navigate to specific screens when the drawer items are clicked.


Go through the complete Flutter navigation drawer example for better understanding.

import 'package:flutter/material.dart';
import 'package:flutter_navigation_drawer/messages.dart';
import 'package:flutter_navigation_drawer/settings.dart';

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

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Tutorials',
      initialRoute: '/',
      routes: {
    // When navigating to the "/" route, build the Main widget.
    '/': (context) => Main(),
    '/messages': (context) => Messages(),
    '/settings': (context) => Settings()
  },
      // home: Main(),
    );
  }
}

class Main extends StatelessWidget {


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Flutter Navigation Drawer')),
      body: Center(child: Text('Home')),
      drawer: Drawer(
        // Add a ListView to the drawer. This ensures the user can scroll
        // through the options in the drawer if there isn't enough vertical
        // space to fit everything.
        child: ListView(
          // Important: Remove any padding from the ListView.
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Center(child:Text('Header Area')),
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
            ),
            ListTile(
              title: Text('Messages'),
              onTap: () {
                Navigator.pop(context);
                Navigator.pushNamed(context, '/messages');
              },
            ),
            ListTile(
              title: Text('Settings'),
              onTap: () {
                Navigator.pop(context);
                Navigator.pushNamed(context, '/settings');
              },
            ),
          ],
        ),
      ),
    );
  }
}


Wednesday, 22 January 2020

What should be kept in mind while starting to learn fluuter mobile App Development from Scratch



If you are starting to learn Flutter Development from scratch, here in this article I will note down some points to keep in mind while learning to code awesome android and iOS mobile App using Flutter and Dart.

  1. Flutter Basics
  1. Core Features
  1. Advance core Features
  1. Flutter internals
  1. Native Device Features
  1. State Management
  1. Keeping the knowledge along with the updating Flutter and Dart Versions
  1. Learn theory
  1. Learn by doing by Developing Projects using the technique of example driven learning.
  1. Develop multiple Apps to know how and when to apply a certain feature, and keep in mind to learn these feature by practically applying will benefit you the most.


Be well prepared yourself to build more apps from your own idea.

Make notes along with learning, keeping checking your knowledge by self-examining and testing.

Join Flutter groups on Facebook and LinkedIn and read the discussion to gain knowledge.
If you get stuck at some point you may ask question, also.

Know and follow the experience developers and teacher of Flutter and Dart, follow them and get engaged into discussion with them.

Following are some step by step points

1- Dart Language Basics
2- Flutter Basics
3- Debugging
4- Flutter Widgets, styling and App logic
5- Responsive and adoptive UIS
6- Flutter advance widgets and Internals
7- Navigation and Multiple screens
8- Statement Management
9-  User input and Forms
10- How to connect Flutter App with the Web
11- User Authentication
12- Animations in Flutter
13- Using device features (camera, location etc)
14- Running Native code into Flutter :Java for Android or Swift for iOS
15- How to Publish the App to Play Store or App store
16- How to develop great mobile Apps

Sunday, 12 January 2020

Flutter Developer Job Interview Questions

This list contains some questions that can be asked from flutter Developer candidate applying for a Flutter Developer position.


Q1: Define the difference between a StatelessWidget and a StatefulWidget in Flutter?

Q2: How do explain the Stateful Widget Lifecycle?

Q3: What is WidgetsBindingObserver define its usage?

Q4: What is Flutter tree shaking?

Q5: What is a Spacer widget?

Q6:  What is the difference between hot restart and hot reload?

Q7:  What is an InheritedWidget?

Q8:  Why is the build() method on State and not StatefulWidgets?

Q9: What is a pubspec file in Dart?

Q10: How Flutter native generates the native code?

Q11:  What is a Navigator and what are Routes in Flutter?

Q12:  What is a PageRoute?

Q13: Explain async, await and Futures.

Q14:  How can you update a ListView dynamically?

Q15:  What is a Stream?

Q16:  What are keys in Flutter and when should you use it?

Q17:  What are GlobalKeys?

Q18:  When should you use mainAxisAlignment and crossAxisAlignment?

Q19: When can you use double.INFINITY?

Q20: What is Ticker, Tween and AnimatedBuilder?

Q20: What is ephemeral state?

Q21: What is an AspectRatio widget used for?

Q22: How would you access StatefulWidget properties from its State?

Q23: Is there a suggested limit to the number of FloatingActionButtons a screen can have?

Q24: Mention two or more operations that would require you to use or return a Future.

Q25: What is the purpose of a SafeArea?

Q25: When to use a mainAxisSize?

Q26: SizedBox VS Container?

Q27: List the Visibility widgets in flutter and the differences?

Q28: Can we use Color and Decoration property simultaneously in the Container?

Q29: In order for the CrossAxisAlignment.baseline to work what is another property that we need to set?

Q30: when should we use a resizeToAvoidBottomInset?

Q31: What is the difference between 'as','show' and 'hide' in an import statement?

Q32: What is the importance of a TextEditingController?

Q33: Why do we use a Reverse property in a Listview?

Q34: Difference between a Modal and Persistent BottomSheet with an example?

Q35: How is an Inherited Widget different from a Provider?

Q36: What is an UnmodifiableListView?

Q37: Difference between these operators "?? and ?."

Q38: What is the purpose of ModalRoute.of()?

Q39: Difference between a Navigator.pushNamed and Navigator.pushReplacementNamed?

Q40: What is a vsync?

Q41: When does the animation reach completed or dismissed status?

Q42: Difference between AnimationController and Animation?

Q43: When to use a SingleTickerProviderStateMixin and TickerProviderStateMixin?

Q44: Define a TweenAnimation ?

Q45: State the importance of a Ticker ?

Q46: Why do we need a mixins ?

Q47: Difference between getDocuments() vs snapshots()?

Q48: Give an introduction BLoC Pattern for state Management in Flutter?

Q49: what is Provider?

Q50: How to make Api call in flutter?