skip to Main Content

In the above code I used Sized Box Widget but it didn’t gives me anything?
How can I add space in it?

Android Emulator Images

image

Padding(padding: EdgeInsetsDirectional.fromSTEB(24, 4, 24, 0),
         child: 
              Row(mainAxisSize: MainAxisSize.max,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                'Discount',
                                style: AppTheme.of(context).subtitle2,
                              ),
                              SizedBox(height: 20,),
                              Text(
                                '₹ ${Provider.of<Cart>(context,listen:false).discountPrice}',
                                style: AppTheme.of(context).subtitle1,
                              ),
                            ],
                          ),
                        ),

3

Answers


  1. wrap with container/sizebox and add in row mainAxisAlignment: MainAxisAlignment.spaceAround

    Login or Signup to reply.
  2. Using TextSpan() widget is better than instead of Row(). Like that.

    RichText(
        text: TextSpan(
      children: [
        TextSpan(text: 'Discount',style: AppTheme.of(context).subtitle2,),
        WidgetSpan(
            child: SizedBox(
          width: 20, // your of space
        ),),
        TextSpan(text: "${Provider.of<Cart(context,listen:false).discountPrice}",
    style: AppTheme.of(context).subtitle1,),
      ],
    ),),
    

    Edit: but I think in your question your code and your screen shoot is different. Please ask clearly. ** My answer is to space between horizontal text widget. **

    Login or Signup to reply.
  3. That’s a quite good approach to use SizedBox in this case, but you need to set width instead of height.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search