skip to Main Content

this is my first time trying something by myself (beginner) , i have wrote these codes and my problem is there’s a specific text that wrote , doesn’t show up in the application when i run it even tho i get no errors or dead codes and this is what i wrote

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    var materialApp = MaterialApp(
      title: 'Unknown driver',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Unkown driver'),
        ),
      ),
    );
    return materialApp;
  }}
Widget mylayouWidget() {
  return const Align(
    alignment: Alignment(0,0),
  child: Text(
      "Unknown but available for u!",
      style: TextStyle(fontSize: 50),
  )
  );
}

this is what i got

enter image description here

why didn’t these show up?

Widget mylayouWidget() {
  return const Align(
    alignment: Alignment(0,0),
  child: Text(
      "Unknown but available for u!",
      style: TextStyle(fontSize: 50),
  )
  );
}

2

Answers


  1. It is because you haven’t call the mylayouWidget(). You need to use it on body.

    home: Scaffold(
            appBar: AppBar(
              title: const Text('Unkown driver'),
            ),
            body: mylayouWidget()
          ),
    
    Login or Signup to reply.
  2. You are never calling your myLayouWidget. Fixed and made your code easier to read

    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      Widget mylayouWidget() {
        return Center(
            child: Text(
                "Unknown but available for u!",
                style: TextStyle(fontSize: 50),
            ),
        ),
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Unknown driver',
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Unkown driver'),
            ),
            body: mylayouWidget()
          ),
        );
      }  
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search