free geoip
52

Dart Basics: Create a Hello World App in Android Studio

If you’re new to mobile development with Flutter and Dart, learning to build a simple Hello World app is the…

If you’re new to mobile development with Flutter and Dart, learning to build a simple Hello World app is the best place to begin. Dart is the primary programming language used in Flutter for building fast, cross-platform mobile applications. In this guide, we’ll show you how to create a basic app that displays “Hello World” using Dart in Android Studio.

Dart Hello World App in Android Studio

Step-by-Step Guide:

1. Set Up Your Environment

Before you start coding, make sure you have Android Studio installed, along with the Flutter and Dart plugins enabled.

2. Create a New Flutter Project

  • Open Android Studio
  • Click on “New Flutter Project”
  • Choose “Flutter Application” and proceed
  • Set your project name (e.g., hello_world_flutter)
  • Select your Flutter SDK path and click Finish

3. Write Your Dart Code

Navigate to the lib/main.dart file and replace the content with the following code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends <a href="https://aliendro.id/create-ui-with-statelesswidget-in-dart/">StatelessWidget</a> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello World App',
home: Scaffold(
appBar: AppBar(
title: Text('Hello World'),
),
body: Center(
child: Text('Hello World!', style: TextStyle(fontSize: 24)),
),
),
);
}
}
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends <a href="https://aliendro.id/create-ui-with-statelesswidget-in-dart/">StatelessWidget</a> { @override Widget build(BuildContext context) { return MaterialApp( title: 'Hello World App', home: Scaffold( appBar: AppBar( title: Text('Hello World'), ), body: Center( child: Text('Hello World!', style: TextStyle(fontSize: 24)), ), ), ); } }
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Hello World App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hello World'),
        ),
        body: Center(
          child: Text('Hello World!', style: TextStyle(fontSize: 24)),
        ),
      ),
    );
  }
}

4. Run the App

Click on the green play button or press Shift + F10 to run your Hello World app on a connected device or emulator.

Conclusion:

This simple Hello World app demonstrates how to use Dart in Flutter via Android Studio. From here, you can explore widgets, layout controls, and navigation in Flutter apps. For more Dart documentation and tutorials, visit the official Dart website.

rysasahrial

Leave a Reply

Your email address will not be published. Required fields are marked *