Home > Blockchain >  is there a way to custom build a container in flutter?
is there a way to custom build a container in flutter?

Time:09-10

I would create a custom container and add properties like id to it I tried doing it like this. what I would like is to create a container which has a unique id assigned to it.

class Tile extends Container
{
  late int id;
 late int position;
  Tile({Key? key}) : super(key: key);
}

CodePudding user response:

You can create custom class like:

class Tile extends StatelessWidget {
  late int id;
  late int position;
  Tile({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

CodePudding user response:

You can choose one of the following two codes:

class Tile extends Container {
  Tile({Key? key, required int id, required int position})
      : super(
          key: key,
          child: ......,
        );
}

or

class Tile extends StatelessWidget {
  const Tile({Key? key, required this.id, required this.position})
      : super(key: key);
  final int id;
  final int position;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ......,
    );
  }
}
  • Related