1

This is my starting code for flutter

class MyHomePage extends StatefulWidget {
      const MyHomePage({Key? key, required this.title}) : super(key: key);
    
      final String title;
      @override
      // ignore: library_private_types_in_public_api
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      final formkey = GlobalKey<FormState>();
      File? inchargePic;
      File? support1Pic;
      File? support2Pic;
      File? kmPic;
      bool _isExpanded = false;
      TextEditingController totalKMController = TextEditingController();
    
      @override
      Widget build(BuildContext context) {
        final size = MediaQuery.of(context).size;
        return Scaffold(
          appBar: AppBar(
            centerTitle: true,
            title: Text(widget.title),
          ),
          body: SizedBox(
            height: size.height,
            width: size.width,
            child: SingleChildScrollView(
              padding: const EdgeInsets.all(20),
              physics: const BouncingScrollPhysics(),
              child: Column(
                children: [
                  inchargeName(),
                  space(),
                  inchargeImage(),
                  space(),
                  addSupport(),
                  space(),
                  kmAndImagePicWidget(size.height, size.width),
                  space(),
                  elevatedButton(),
                ],
              ),
            ),
          ),
        );
      }

This is where i called the function onpressed top add widgets.

 SizedBox addSupport() {
    return SizedBox(
      child: SingleChildScrollView(
        child: Column(
          children: [
            ElevatedButton(
              style: ElevatedButton.styleFrom(
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10))),
              onPressed: () {
                setState(() {
                  _isExpanded = !_isExpanded;
                });
              },
              child: const Text("Add Support"),
            ),
            space(),
            if (_isExpanded) support1()
          ],
        ),
      ),
    );
  }

The exact problem is i can add support1 when pressed but i also want support2 widget which i have added but not know how how to call it.

il_raffa
  • 5,090
  • 129
  • 31
  • 36
Devendiran
  • 99
  • 9
  • possibly duplicate of https://stackoverflow.com/questions/51605131/how-to-add-the-widgets-dynamically-to-column-in-flutter || https://stackoverflow.com/questions/64342662/dynamically-add-a-widget-on-press-of-button – RaZzLe Feb 23 '23 at 05:17
  • you can use list and use listview builder to add dynamic values on list when you click add support button. – Nikunj Ramani Feb 23 '23 at 05:17

0 Answers0