First Flutter Application
Create the first flutter application using command line.
In this blog post, we will be discussing how to create a flutter application and run it. A flutter application is created using the Dart programming language and the Flutter SDK. The dart:ui library provides the basis for all of the Flutter UI components. The following steps will be covered:
Creating a new Flutter project
Adding assets to the project
Writing the Dart code
Running the application on an emulator or device
Creating a new Flutter project:
To create a new flutter project, open the terminal and enter the following command:
$ flutter create myapp
$ cd myapp
$ flutter run
This will create a new flutter project with the name myapp. The project will contain all the necessary files and folders for a flutter project.
Adding assets to the project:
Assets are files that are bundled with the application. They can be images, videos, fonts, etc. To add assets to the project, create a new folder called assets in the root of the project. Then, add your assets to this folder. For example, to add an image called my_image.png, add it to the assets folder.
Writing the Dart code:
The Dart code for a flutter project is written in the main.dart file. This file contains the code for the application's UI and logic. The following code creates a simple button that says "Press me!":
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('Flutter App'), ), body: Center( child: RaisedButton( child: Text('Press me!'), onPressed: () {}, ), ), ), ); }}
Running the app on an emulator/ device:
To run the application on an emulator or device, use the following command:
$ flutter run --release
This command will build and run the application on an attached device or simulator. If no devices are attached, this command will launch an emulator.