The Wayback Machine - https://web.archive.org/web/20250114020833/https://www.geeksforgeeks.org/creating-a-simple-application-in-flutter/
Open In App

Creating a Simple Application in Flutter

Last Updated : 18 Oct, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Flutter is an open-source cross-platform mobile application development SDK created by Google. It is highly user-friendly and builds high-quality mobile applications. The intention behind this article is to guide readers through the process of building an application through flutter by creating a simple Flutter App on Android Studio. To start creating a Flutter application we have to first create a flutter project and many other things, for that follow the steps mentioned below:

Create a New Flutter Project

Step 1: Open the Android Studio IDE and select Start a new Flutter project.

Note:  if you like to create a flutter project using terminal use the below command and jump  right into step 6

$ flutter create flutter_app

replace the ‘ flutter_app ‘ with your project name

creating a new project

Step 2: Select the Flutter Application as the project type. Then click Next.

selecting the application builder

Step 3: Verify the Flutter SDK path specifies the SDK’s location (select Install SDKâ€Ķ if the text field is blank).

Step 4: Enter a project name (for example, myapp). Then click Next.

naming the application

Note:
1. Project name: flutter_app
2. Flutter SDK Path: <path-to-flutter-sdk>
3. Project Location: <path-to-project-folder>
4. Description: Flutter based simple application

Step 5: Click Finish and wait till Android Studio creates the project.

naming the flutter package

Step 6: Edit the code

After successfully creating a file, we can edit the code of the application to show the output we want. Android Studio creates a fully working flutter application with minimal functionality. Let us check the structure of the application and then, change the code to do our task.

The structure of the application and its purpose are as follows?

file structure in flutter

We have to edit the code in main.dart as mentioned in the above image. We can see that Android Studio has automatically generated most of the files for our flutter app.

Replace the dart code in the lib/main.dart file with the below code:

Dart




// Importing important packages require to connect
// Flutter and Dart
import 'package:flutter/material.dart';
 
// Main Function
void main() {
// Giving command to runApp() to run the app.
 
/* The purpose of the runApp() function is to attach
the given widget to the screen. */
  runApp(const MyApp());
}
 
// Widget is used to create UI in flutter framework.
 
/* StatelessWidget is a widget, which does not maintain
any state of the widget. */
 
/* MyApp extends StatelessWidget and overrides its
build method. */
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
 
// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // title of the application
      title: 'Hello World Demo Application',
      // theme of the widget
      theme: ThemeData(
        primarySwatch: Colors.lightGreen,
      ),
      // Inner UI of the application
      home: const MyHomePage(title: 'Home page'),
    );
  }
}
 
/* This class is similar to MyApp instead it
returns Scaffold Widget */
class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;
 
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      // Sets the content to the
      // center of the application page
      body: const Center(
          // Sets the content of the Application
          child: Text(
        'Welcome to GeeksForGeeks!',
      )),
    );
  }
}


Output:

sample application in flutter


Looking to become an expert in Android App Development? Whether you're a student or a professional aiming to advance your career in mobile app development, our course, "Android App Development with Kotlin," available exclusively on GeeksforGeeks, is the perfect fit for you. Gain hands-on experience with Kotlin, the modern language preferred by Android developers worldwide. This course will guide you through the essentials of Android app development, from the basics to advanced techniques, using practical projects and real-world scenarios. Ideal for beginners and those looking to enhance their existing skills, this course will equip you with the expertise needed to build high-quality, robust Android applications. Ready to master Android development? Enroll now and elevate your career to new heights!


Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg