Positional arguments must occur before named arugments, And Too many positional arguments on flutter

103

Solution 1

Change the name of class as your class name, I created TextFormField below the name

        import 'package:flutter/material.dart';
    
    class TabScreen extends StatefulWidget {
      const TabScreen({Key? key}) : super(key: key);
    
      @override
      _TabScreenState createState() => _TabScreenState();
    }
    
    class _TabScreenState extends State<TabScreen> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            leading: IconButton(onPressed: () {}, icon: Icon(Icons.exit_to_app)),
          ),
          body: SingleChildScrollView(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.symmetric(
                          vertical: 35.0,
                        ),
                        child: Text(
                          'Forgot Password',
                          style: TextStyle(
                              color: Colors.blue,
                              fontWeight: FontWeight.bold,
                              fontSize: 20.0),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 12, 0, 0),
                        child: Container(
                          child: Icon(Icons.exit_to_app),
                        ),
                      ),
                    ],
                  ),
                  Container(
                    height: 440.0,
                    color: Colors.transparent,
                    child: Container(
                      decoration: new BoxDecoration(
                          color: Colors.blue,
                          borderRadius: new BorderRadius.only(
                            topLeft: const Radius.circular(40.0),
                            topRight: const Radius.circular(40.0),
                          )),
                      child: new Align(
                        alignment: Alignment.topCenter,
                        child: Padding(
                          padding: EdgeInsets.symmetric(vertical: 40),
                          child: Column(
                            children: [
                              Text(
                                'Masukkan Email',
                                style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 14,
                                    fontWeight: FontWeight.bold),
                              ),
                              Container(
                                margin: EdgeInsets.all(15),
                                child: TextFormField(showCursor: true, cursorColor: Colors.white,
                                  style: TextStyle(
                                    fontSize: 18,
                                    color: Colors.white,
                                    fontWeight: FontWeight.w600,
                                  ),
                                  decoration: InputDecoration(
                                    border: OutlineInputBorder(
                                      borderRadius: BorderRadius.circular(10.0),
                                    ),
                                    focusColor: Colors.white,
                                    focusedBorder: OutlineInputBorder(
                                      borderSide:
                                      const BorderSide(color: Colors.black, width: 1.0),
                                      borderRadius: BorderRadius.circular(10.0),
                                    ),
                                    // fillColor: Colors.grey,
    
                                    hintText: "Email",
                                  ),
                                ),
                              ),
                            ],
                          ),
                          // sizedBox(height: 20,)
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        );
      }
    }

Solution 2

use this code, it will work

import 'package:flutter/material.dart';

class ForgotPassword extends StatefulWidget {
  const ForgotPassword({Key? key}) : super(key: key);

  @override
  _ForgotPasswordState createState() => _ForgotPasswordState();
}

class _ForgotPasswordState extends State<ForgotPassword> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(onPressed: () {}, icon: Icon(Icons.exit_to_app)),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.symmetric(
                  vertical: 35.0,
                ),
                child: Text(
                  'Forgot Password',
                  style: TextStyle(
                      color: Colors.blue,
                      fontWeight: FontWeight.bold,
                      fontSize: 20.0),
                ),
              ),
              Padding(
                padding: EdgeInsets.fromLTRB(0, 12, 0, 0),
                child: Container(
                  child: Image.asset('assets/forgot password 1.png'),
                ),
              ),
              new Container(
                height: 440.0,
                color: Colors.transparent,
                child: Container(
                  decoration: new BoxDecoration(
                      color: Colors.blue,
                      borderRadius: new BorderRadius.only(
                        topLeft: const Radius.circular(40.0),
                        topRight: const Radius.circular(40.0),
                      )),
                  child: new Align(
                    alignment: Alignment.topCenter,
                    child: Column(
                      children: [
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 40),
                          child: Text(
                            'Masukkan Email',
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 14,
                                fontWeight: FontWeight.bold),
                          ),
                        ),
                        TextFormField(.....)
                      ],
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 20,
              )
            ],
          ),
        ),
      ),
    );
  }
}
Share:
103
Imam Rizky GANTENG
Author by

Imam Rizky GANTENG

Updated on January 01, 2023

Comments

  • Imam Rizky GANTENG
    Imam Rizky GANTENG over 1 year

    I had some error that says "Positional arguments must occur before named arguments" and " too many positional arguments" when i wanted to add an textformfield on my code, the design will looks like this

    I need put the textformfield below the text how do i add the textformfield without making any error?

    heres my code

    import 'package:flutter/material.dart';
    
    class ForgotPassword extends StatefulWidget {
      const ForgotPassword({Key? key}) : super(key: key);
    
      @override
      _ForgotPasswordState createState() => _ForgotPasswordState();
    }
    
    class _ForgotPasswordState extends State<ForgotPassword> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            leading: IconButton(onPressed: () {}, icon: Icon(Icons.exit_to_app)),
          ),
          body: SingleChildScrollView(
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.symmetric(
                      vertical: 35.0,
                    ),
                    child: Text(
                      'Forgot Password',
                      style: TextStyle(
                          color: Colors.blue,
                          fontWeight: FontWeight.bold,
                          fontSize: 20.0),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(0, 12, 0, 0),
                    child: Container(
                      child: Image.asset('assets/forgot password 1.png'),
                    ),
                  ),
                  new Container(
                    height: 440.0,
                    color: Colors.transparent,
                    child: Container(
                      decoration: new BoxDecoration(
                          color: Colors.blue,
                          borderRadius: new BorderRadius.only(
                            topLeft: const Radius.circular(40.0),
                            topRight: const Radius.circular(40.0),
                          )),
                      child: new Align(
                        alignment: Alignment.topCenter,
                        child: Padding(
                          padding: EdgeInsets.symmetric(vertical: 40),
                          child: Text(
                            'Masukkan Email',
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 14,
                                fontWeight: FontWeight.bold),
                          ),
                          sizedBox(height: 20,)
                        ), 
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    
    • Praveen Soni
      Praveen Soni over 2 years
      at end, you passed sizedBox in padding, use column instead,
    • Imam Rizky GANTENG
      Imam Rizky GANTENG over 2 years
      no its same i cant add any column, container, child
  • Imam Rizky GANTENG
    Imam Rizky GANTENG over 2 years
    it showing error when adding sizedbox or child [like this] (imgur.com/a/weHnrGN)
  • Imam Rizky GANTENG
    Imam Rizky GANTENG over 2 years
    it put the textfield below the blue container, i wanted the textfield below the text
  • DimasGs
    DimasGs over 2 years
    i've edited my answer, take a look
  • Rakesh Saini
    Rakesh Saini over 2 years
    Try this code in your class