Home > Enterprise >  Does dart/flutter have the functionality to set UI properties on widgets at a class level?
Does dart/flutter have the functionality to set UI properties on widgets at a class level?

Time:12-20

Similar to using css and html. Goal would be to have a single file where we can set the color size or whatever other property for the Column, or DropDownMenu class and not have to repeat for every instance of the class.

CodePudding user response:

Try the following code:

class CustomColumn extends StatelessWidget {
  const CustomColumn({super.key, required this.children});

  final List<Widget> children;

  @override
  Widget build(BuildContext context) {
    return Column(
      // You can style your Column here
      children: children,
    );
  }
}

class CustomDropdownButton extends StatelessWidget {
  const CustomDropdownButton({super.key, required this.items, required this.onChanged});

  final List<DropdownMenuItem> items;
  final void Function(dynamic) onChanged;

  @override
  Widget build(BuildContext context) {
    return DropdownButton(
      items: items,
      onChanged: onChanged,
      // You can style your DropdownButton here
    );
  }
}
  • Related