Flutter-How to display existing TextFormField widget in RenderBox component?

74 Views Asked by At

How to add the existing widget in RenderBox component?. I want to add the TextFormField widget in the paint method of render box. I have included the code snippet I used and a screenshot of the output

Code snippet:

class HomePage extends StatelessWidget {
  const HomePage({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TextFormField'),
      ),
      body: SafeArea(
        child: Center(child: MyWidget()),
      ),
    );
  }
}

class MyWidget extends SingleChildRenderObjectWidget {
  @override
  RenderObject createRenderObject(BuildContext context) {
    return _RenderMyWidget();
  }
}

class _RenderMyWidget extends RenderBox {
  @override
  bool hitTestSelf(Offset position) => true;

  @override
  bool get sizedByParent => true;

  /// This replaces the old performResize method.
  @override
  Size computeDryLayout(BoxConstraints constraints) {
    return constraints.biggest;
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    final Canvas canvas = context.canvas;

    // return TextFormField(
    //   decoration: const InputDecoration(
    //     icon: Icon(Icons.person),
    //     labelText: 'Name *',
    //   ),
    // );
  }
}

Output screenshot : enter image description here

0

There are 0 best solutions below