Tuesday, February 5, 2019

Flutter

How to install Flutter in VsCode and run Android Emulator
Course Syllabus
  • Adding Animations
  • Responsive and Adaptive User Interface and Apps
  • Navigations and Muitleple Screens
  • User Input and Forms
  • State Management(BLOC)
  • Http (Request, Response)
  • Adding Authentications
  • Using Device Features(Camera, maps, Locations)
  • Firebase, Image Upload, Push Notifications
  • Publishing to the App Store

Dart Flutter MaterialApp / Scaffold


.....................................................................................................................................................................................................................................
Notes
      debugShowCheckedModeBanner: false,
accentColor: Colors.indigoAccent
When the page is scrolling,
ie accentColor



return Scaffold(
  resizeToAvoidBottomPadding: false,

................................................................................................................................
Step : #1 [ Basic Search ]
visit the link -  https://flutter.dev/
and Click the Get started button


Step : #2 [ Install ]
   Click Get Start to start downloading Fluttter SDK




Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1
Step : #1



Vysor Extension for chorme, it help full to connect real device



# If necessary, you can check your current Flutter version with the command:
 flutter --version

Creating a New Flutter Project

# New Flutter application
flutter create flutter_http

# Open this up inside of VS Code
cd flutter_http && code .

pub publish --dry-run

flutter pub get

flutter doctor --android-licenses


......................................................................................................................................................................................................................................
Flutter : #1 [Example of Hello  world ]
import 'package:flutter/material.dart';
void main(){
  runApp(myApp());
}

class myApp extends StatelessWidget{
  @override  Widget build(BuildContext context){
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hello World'),
          backgroundColor: Colors.pinkAccent,
          centerTitle: true,
        ),
        body: Center(
            child:Text('Body part',
              style: TextStyle(
                  color: Colors.pink, fontSize: 30              ),
        ),

        ),
backgroundColor: Colors.white,
      ),
    );
  }
}
Happy Coding :)
..................................................................................................................................................................................................................................
Flutter : #1.1 [Example of StatelessWidget and StatefulWidget ]
import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @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),
      ), // This trailing comma makes auto-formatting nicer for build methods.    );
  }
}
Happy coding :)
..................................................................................................................................................................................................................................
Flutter : #1.2 [Example of AppBar  ]
import 'package:flutter/material.dart';

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

class MyHello extends StatelessWidget {
  @override  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Home',
      theme: ThemeData(
          primarySwatch: Colors.red,
          accentColor: Colors.red,
          appBarTheme: AppBarTheme(color: Colors.red)),
      home: Myhome(),
    );
  }
}

class Myhome extends StatefulWidget {
  @override  _MyhomeState createState() => _MyhomeState();
}

class _MyhomeState extends State<Myhome> {
  @override  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        
        leading: IconButton(
          
          onPressed: (){},
          icon: Icon(Icons.menu)
        ),
        
        actions: <Widget>[
          InkWell(
            child: IconButton(
              padding: const EdgeInsets.only(right: 20),
              icon: Icon(Icons.access_alarms, 
              
              ),
              ),
          ),
          IconButton(
            onPressed: (){},
            padding: const EdgeInsets.only(right: 10),
            icon: Icon(Icons.search),
            )
        ],
        
        title: Text('Welcome Page'),
        titleSpacing: 40,
        centerTitle: true,
      ),
    );
  }
}



..................................................................................................................................................................................................................................
Flutter : #1.3 [Example of AppBar  ]
import 'package:flutter/material.dart';
void main()=>runApp(MyApp());class MyApp extends StatefulWidget{
  @override  _MyAppState createState()=>_MyAppState();
}class _MyAppState extends State<MyApp>{
  @override  Widget build(BuildContext context){    return MaterialApp(      title: 'Home',
      theme: ThemeData(
        primaryColor: Colors.purple[900]
      ),      home: Scaffold(        appBar: AppBar(
          title: Text('Firebase connection Demo'),
          centerTitle: true,
        ),
      ),

    );
  }
}
..................................................................................................................................................................................................................................
Flutter : #2 [ Load image from Assets]
- Adding ImagesAssets to a Flutter Project
- create a new Directory called assets/images




Single Images 



All Images 


import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override  Widget build(BuildContext context){
    return Container(
      decoration: BoxDecoration(
        color: Colors.purple      ),
      child: Center(
        child: Image.asset('assets/images/images.jpg',
        //child: Image.asset('images/images.jpg',
fit: BoxFit.cover, width: 100.0, height: 100.0, ), ), ); } }
..................................................................................................................................................................................................................................
Flutter : #3 [FlatButton]

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

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

class MyApp extends StatelessWidget{
  @override  Widget build (BuildContext context){
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hello world'),
        ),
        body: Center(
          child: FlatButton(
            padding: EdgeInsets.symmetric(vertical: 30.0, horizontal: 90.0),
            color: Colors.purple,
            textColor: Colors.black,
            splashColor: Colors.cyan,
            //highlightColor: Colors.amber,            onPressed: (){}, // Anonymous function            child: Text('FlatButton',
            style: TextStyle(
             // color: Colors.white,              fontSize: 24.0            ),
            ),
          ),
        ),
      ),

    );

  }
}

..................................................................................................................................................................................................................................
Flutter : #4 [RaisedButton ]


import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget{
  @override  Widget build(BuildContext context){
    return MaterialApp(
      home: Scaffold(
        appBar:AppBar(
          title: Text('Home')
        ),
        body: Center(
          child: RaisedButton(
            color: Colors.white,
            textColor: Colors.black,
            splashColor: Colors.cyan,
            padding: EdgeInsets.symmetric(vertical: 30.0, horizontal: 30.0),
            elevation: 10.0,
            highlightElevation: 30.0,
            shape: Border.all(width: 2.0, color: Colors.black),
            onPressed: (){},
            child: Text('RaiseButton',
              style: TextStyle(
                color: Colors.red,
                fontSize: 24.0              ),
            ),
          ),
        ),
      )

    );
  }
}
..................................................................................................................................................................................................................................
Flutter : #5 [FloatingActionButton]


import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget{
  @override  Widget build(BuildContext context){
    return MaterialApp(
      home:Scaffold(
        appBar: AppBar(
          title: Icon(Icons.accessible_forward),

        ),
        floatingActionButton: FloatingActionButton(
          onPressed: (){},
          child: Icon(Icons.add          ),
          foregroundColor: Colors.pink,
          backgroundColor: Colors.green,
          shape: RoundedRectangleBorder(),
        ),
        body: Center(
          child: RaisedButton(
            child: Icon(
              Icons.add            ),

          ),

        ),
      ),
    );
  }
}
..................................................................................................................................................................................................................................
Flutter : #6 [Example of Hello  world  ]


..................................................................................................................................................................................................................................
Flutter : #7 [Textfield  ]


import 'package:flutter/material.dart';

void main()=>runApp(MyApp());
class MyApp extends StatelessWidget{
  @override  Widget build(BuildContext context){
    return MaterialApp(
      title: 'Text Fields',
      theme: ThemeData(
        primaryColor: Colors.lightBlueAccent      ),
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget{
  @override  _MyHomePageState createState()=>_MyHomePageState();
  }
class _MyHomePageState extends State<MyHomePage>{
@override  Widget build (BuildContext context){
  return Scaffold(
    body: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(18.0),
          child: TextField(
            decoration: InputDecoration(
              //hintText: 'username',              prefix: Icon(Icons.account_circle),
              helperText: 'please enter username',
              labelText:'Username',
              border: OutlineInputBorder(),
            ),
            maxLength: 20,
            style: TextStyle(
              color: Colors.red,
              fontSize: 25.0,
            ),
          ),
        ),

      ],
    ),

  );
}
}
Flutter : #9 [Example of Hello  world  ]

..................................................................................................................................................................................................................................
Flutter : #10 [Example of Hello  world  ]



..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]
..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]

..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]
..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]
..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]

..................................................................................................................................................................................................................................
Flutter : #2 [ Http ]




import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;

void main()=>{
  runApp(MaterialApp(
  title:'Android App',
    home: MyApp(todos:getData())
))
};
Future<Todos>getData() async {
  final response = await http.get('https://jsonplaceholder.typicode.com/todos/1');
  if (response.statusCode == 200) {
    return Todos.fromJson(json.decode(response.body));
  }
  else {
    throw Exception('No response from server');
  }
}

class Todos {
  final int user;
  final int id;
  final String title;
  final bool completed;
  Todos({this.user, this.id,this.title, this.completed });
  factory Todos.fromJson(Map<String, dynamic> json) {
    return Todos(
        user:json['userId'],
      id:json['id'],
      title:json['title'],
      completed:json['completed']
    );
  }
}
class MyApp extends StatelessWidget {
  Future<Todos>todos;
  MyApp({Key key, this.todos}): super(key:key);
  @override  Widget build(BuildContext context){
    return Scaffold(
      body: Center(
        child: FutureBuilder<Todos>(
            future: todos,
            builder: (context,snapshot){
              if(snapshot.hasData){
                return Text(snapshot.data.title);
              }
              return CircularProgressIndicator();
            }
        ),
      )
    );
  }

}
..................................................................................................................................................................................................................................
Flutter : #2 [Json  ]

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';

void main()=>{
 runApp(MaterialApp(
   title: 'Home',

   theme: ThemeData(
     primarySwatch: Colors.red   ),
   home: MyRestApi(),

 ))
};
class MyRestApi extends StatefulWidget{
  @override  _MyRestApiState createState()=> _MyRestApiState();
}
class _MyRestApiState extends State<MyRestApi>{
  Map data;
  List userData;
  Future getData() async {
    final response = await http.get('https://reqres.in/api/users?page=2');
    data=json.decode(response.body);
    setState(() {
      userData=data["data"];
    });
    debugPrint(userData.toString());
  }
  @override  void initState(){
    super.initState();
    getData();
  }
  @overrideWidget build(BuildContext context){
    return Scaffold(
        appBar:AppBar(
          centerTitle: true,
          title: Text('How to call FAKE API'),
        ),
      body:ListView.builder(
        itemCount: userData == null ? 0 : userData.length,
          itemBuilder: (BuildContext context, int index){
          return Card(
            child: Row(
              children: <Widget>[
                CircleAvatar(
                  backgroundImage: NetworkImage(userData[index]["avatar"]),
                ),
                Text("${userData[index]["first_name"]} ${userData[index]["last_name"]}" ,
                style: TextStyle(
                  fontSize: 20,
                ),
                )
              ],
            ),
          );
        }
      ) ,
    );
  }
}

..................................................................................................................................................................................................................................
Flutter : #2 [ MAP ]


import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
  @override  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
  @override  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Maps Sample App'),
          backgroundColor: Colors.green[700],
        ),
        body: GoogleMap( initialCameraPosition: CameraPosition(
          target: LatLng(37.77483, -122.41942),
          zoom: 12           ),
          ),
        ),
    );
  }
}

..................................................................................................................................................................................................................................
Flutter : #2 [GridView  ]

import 'package:flutter/material.dart';
void main()=> runApp(MyApp());
class MyApp extends StatelessWidget{
  @override  Widget build(BuildContext context){
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Home',
      theme: ThemeData(
        backgroundColor: Colors.red,
        accentColor: Colors.yellowAccent,
        primarySwatch: Colors.green,          appBarTheme: AppBarTheme(color:Colors.white, elevation: 5),      ),
      home: MyHome(),
    );
  }
}class MyHome extends StatefulWidget{
  MyHome({Key key, this.title}):super(key:key);
  final String title;
  @override  _MyHomeState createState()=> _MyHomeState();
}class _MyHomeState extends State<MyHome>{
  @override  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Grid View', style: TextStyle(color: Colors.green),),
      ),
      body: GridView.count(
          crossAxisCount: 2,
        children: <Widget>[
          Center(
            child:Text('Hello World'),
          ),
          Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),Center(
            child:Text('Hello World'),
          ),

        ],

      ),
    );
  }
}
..................................................................................................................................................................................................................................
..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]
..................................................................................................................................................................................................................................
Flutter : #2 [Example of Hello  world  ]



No comments:

Post a Comment