Home > Net >  Flutter :The named parameter 'textAlign' isn't defined
Flutter :The named parameter 'textAlign' isn't defined

Time:02-13

class Home extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return Scaffold(
    appBar: AppBar(),
    drawer: Drawer(),
    body: Text(
      "Home page ,Omar OS ",
      style: TextStyle(
          fontSize: 30,
          color: Colors.red,
          fontWeight: FontWeight.bold,
          fontStyle: FontStyle.italic),
    ),
    textAlign: TextAlign.center);
  }
}

Error:

No named parameter with the name 'textAlign'.
lib/main.dart:30
        textAlign: TextAlign.center);
        ^^^^^^^^^
/C:/flutter/packages/flutter/lib/src/material/scaffold.dart:1470:9: Context: Found this candidate, but the arguments don't match.
  const Scaffold({

CodePudding user response:

The textAlign parameter belongs to the Text widget but you've defined it on Scaffold. This should work:

class Home extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return Scaffold(
    appBar: AppBar(),
    drawer: Drawer(),
    body: Text(
      "Home page ,Omar OS ",
      style: TextStyle(
          fontSize: 30,
          color: Colors.red,
          fontWeight: FontWeight.bold,
          fontStyle: FontStyle.italic),
      textAlign: TextAlign.center
    ),
    );
  }
}

CodePudding user response:

  class Home extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          appBar: AppBar(),
          drawer: Drawer(),
          body: Text(
            "Home page ,Omar OS ",
            style: TextStyle(
                fontSize: 30,
                color: Colors.red,
                fontWeight: FontWeight.bold,
                fontStyle: FontStyle.italic),
              textAlign: TextAlign.center),
          );
          
    }
  }
  • Related