skip to Main Content

I want to start coding the onProgress page which is the first page on my app which the user see after opening my app.

I’ve tried doing it like this, but am not sure if the syntax start like this

import 'package:flutter/material.dart';

class OnBoard extends StatelessWidget {
  const OnBoard({super.key});

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Text("Welocome to My App"));
  }
}

2

Answers


  1. Code is almost correct for creating a simple page in Flutter. Here are a few points to improve and ensure it works:

    Scaffold: Wrap your Center widget in a Scaffold. This provides a basic structure for your app, like app bars or floating action buttons.

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
          child: Text("Welcome to My App"),
        ),
      );
    }
    

    MaterialApp: If this is the first page of your app, you need to run it inside a MaterialApp in the main.dart file.

    void main() {
      runApp(MaterialApp(
        home: OnBoard(),
      ));
    }
    

    Fix Typo: There’s a typo in your text. It should be "Welcome" instead of "Welocome."

    With these changes, your app will display the "Welcome to My App" text properly when it starts.

    Keep coding—you’re on the right track!

    Login or Signup to reply.
  2. Update Your code with this

    void main() {
          runApp(MaterialApp(
            home: OnBoard(),
          ));
        }
    
    
    class OnBoard extends StatelessWidget {
      const OnBoard({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Welcome'),
          ),
          body: const Center(
            child: Text(
              "Welcome to My App",
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
          ),
        );
      }
    }
    

    HAPPY CODING 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search