'Positional arguments must occur before named arguments

class MyHomePage extends StatelessWidget {
  final String title;

  MyHomePage({Key key, @required this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Container(
          color: Theme.of(context).accentColor,
        ),
      ),
      floatingActionButton: Theme(
        data: Theme.of(context).copyWith(
          colorScheme: Theme.of(context)
              .colorScheme
              .copyWith(secondary: Colors.blueGrey),
        ),
        child: FloatingActionButton(
          onPressed: null,
          child: Icon(Icons.add),
        ),
      ),
      Biodiri(
        nama: "A",
        tanggal: "B-C",
        alamat: "Az- B",
        jeniskelamin: "Laki-Laki",
      )
    );
  }
}


Solution 1:[1]

Not sure if I understand the problem, but try changing the constructor to

MyHomePage({Key? key, required this.title}) : super(key: key);

Your custom class:

class Biodiri {

  String nama;
  String tanggal;
  String alamat;
  String jeniskelamin;

  Biodiri({ required this.nama, required this.tanggal, required this.alamat, required this.jeniskelamin});

}

If your class has any optional (nullable) fields, eg 'alamat', use "String?" as type and do not use "required" for the optional parameter:

class Biodiri {

  String nama;
  String tanggal;
  String? alamat;
  String jeniskelamin;

  Biodiri({ required this.nama, required this.tanggal, this.alamat, required this.jeniskelamin});

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1