How can I add certain ClipPath to every page in flutter by writting the code, one time?

56 Views Asked by At
ClipPath(
        child: Container(
          height: 200,
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              colors: [Color(0xFF7CB342), Color(0xFFDCEDC8)],
            ),
          ),
          child: Center(child: Text('mainPage')),
        ),
      ),

I want to apply this code to every pages that will open in my app, How can i do it?

1

There are 1 best solutions below

0
On BEST ANSWER

You can create a widget like this:

class ClipWidget extends StatelessWidget {
  final Widget? childWidget;

  const ClipWidget({Key? key, this.childWidget}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ClipPath(
      child: Container(
        height: 200,
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            colors: [Color(0xFF7CB342), Color(0xFFDCEDC8)],
          ),
        ),
        child: childWidget),
      );
  }
}

and use it like:

return ClipWidget(childWidget:const Center(child: Text('mainPage')));