No material widget found textfield widgets require a material widget ancestor

后端 未结 6 1808
走了就别回头了
走了就别回头了 2021-02-01 19:49

Hi I am trying to build a login screen in flutter but I am getting below error when opening it.

No material widget found textfield widgets require a mater

相关标签:
6条回答
  • 2021-02-01 19:53

    Error states that TextField widgets require a Material widget ancestor. Simply wrapping your whole loginWidget into Scaffold will solve the problem.

    Widget LoginPage() {
       return new Scaffold(body: *your whole code*)
    }
    
    0 讨论(0)
  • 2021-02-01 19:55

    Just wrap your widget with Material like this:

    @override
    Widget build(BuildContext context) {
      return Material(
        child: YourAwesomeWidget(),
    }
    
    0 讨论(0)
  • 2021-02-01 19:58

    Wrap the code with Scaffold. it works

    0 讨论(0)
  • 2021-02-01 20:09

    Wrap the loginpage function with a Scaffold or a MaterialApp

    Widget LoginPage() {
      return new Scaffold(
        body: Container(
          *the rest of your code*
        ),
      );
    }
    

    or

    Widget LoginPage() {
      return new MaterialApp(
        home: Container(
          *the rest of your code*
        ),
      );
    }
    
    0 讨论(0)
  • 2021-02-01 20:09

    I encountered your same problem. Always remember to enter Scaffold remembering that it must be included as a parent who creates the page, inside it after, you will insert all the widgets you want, but Scaffold after MaterialApp is the second component that must be added if you are creating a new page.

    0 讨论(0)
  • 2021-02-01 20:10

    Since most of the widget asks for material widget as their parent widget

    its a good practice you should use Material() or Scaffold() widget on top of the widget tree and then continue your code.

    @override
    Widget build(BuildContext context) {
      return Material(
        child: body(),
    }
    

    OR

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        child: body(),
    }
    
    0 讨论(0)
提交回复
热议问题