0

I am new to flutter and i am trying out new things.my question is how to pass image from toggle button to next page in flutter? This is the code for toggle button which have image and text in it,I want to pass selected image to next page

    Container(

   child:  SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: ToggleButtons(
          
          borderWidth: 1,
          
          children:<Widget> [
           
            Padding(padding: EdgeInsets.only(left:10),
            child:
            CustomIcon(
              
             text:Text("TATA ACE",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 12),),
              image: Image.asset("images/delivery.png",scale: 9,),
              
              isSelected: isSelected[0],
              bgColor:const Color(0x000000),
            ),),
            Padding(padding: EdgeInsets.only(left:10),
            child:
            CustomIcon(
             text: Text("TATA APE",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 12),),
              image: Image.asset("images/delivery.png",scale: 9,),
              
              isSelected: isSelected[1],
              bgColor: const Color(0x000000),
            ),),

CustomItem class is also defined below

class CustomIcon extends StatefulWidget {
  final Image image;
  final Text text;
  final bool isSelected;
  final Color bgColor;

  const CustomIcon(
      {Key? key,
      required this.text,
      required this.image,
      this.isSelected = false,
      this.bgColor = Colors.black, value1})
      : super(key: key);
  @override
  _CustomIconState createState() => _CustomIconState();
}

class _CustomIconState extends State<CustomIcon> {
  @override
  Widget build(BuildContext context) {
    
    return Container(
      width: 105,
      height: 105,
      decoration: BoxDecoration(
        color: widget.isSelected
            ?  Colors.black : Colors.grey,shape: BoxShape.rectangle,
        borderRadius: const BorderRadius.all(
          Radius.circular(100),
        ),
      ),
      child: Center(
        child: Container(
          padding: EdgeInsets.all(15),
          height: 105,
          width: 105,
          decoration: BoxDecoration(
            color: widget.bgColor,
            borderRadius: const BorderRadius.all(
              Radius.circular(100),
            ),
          ),
          child:Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              widget.image,
              
              widget.text,
            ],
          ),
        ),
      ),
    );
  }
}

I need to pass this text and image to the next page or just image to next screen.

0 Answers0