Saturday, May 27, 2023

Write a program Print welcome message with your name using Flutter

 


To print a welcome message with your name using Flutter, you can follow these steps:


Step 1: Create a new Flutter project

- Open Visual Studio Code and create a new Flutter project using the steps mentioned in the previous response.


Step 2: Update the `lib/main.dart` file

- Open the `lib/main.dart` file in Visual Studio Code.


Step 3: Replace the existing code with the following code:


import 'package:flutter/material.dart';


void main() {

  runApp(MyApp());

}


class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title: 'Welcome App',

      home: Scaffold(

        appBar: AppBar(

          title: Text('Welcome'),

        ),

        body: Center(

          child: Column(

            mainAxisAlignment: MainAxisAlignment.center,

            children: <Widget>[

              Text(

                'Welcome to Flutter!',

                style: TextStyle(fontSize: 24),

              ),

              SizedBox(height: 16),

              Text(

                'Your Name',

                style: TextStyle(fontSize: 18),

              ),

            ],

          ),

        ),

      ),

    );

  }

}



Step 4: Replace `'Your Name'` with your actual name

- In the code above, you'll see a `Text` widget with the placeholder text `'Your Name'`.

- Replace `'Your Name'` with your actual name or any name you want to display.


Step 5: Run the app

- Save the changes made to the `lib/main.dart` file.

- Open the terminal in Visual Studio Code and navigate to your Flutter project directory.

- Run the following command to start the app on an emulator or connected device:


  flutter run


- The app will build and launch, and you should see the welcome message along with the name you provided in the center of the screen.


That's it! You have created a Flutter app that displays a welcome message with your name. Feel free to customize the app further by adding more widgets, styling, or functionality as per your requirements.