How to set colored line to end of card in flutter?

Viewed 1125

i was tring to make this to available to my list of expenses.

Expected output:

card view with border at end

My Output:

card view with no border

i tried using verticalDivider( thickness:2.0, color:Colors.red ) and Container( width:2.0, color:Colors.red ) wrap with IntrinsticHeight. it has to take up card's height. here my output's code for card view.

Card(
     margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
     elevation: 2.0,
        child: InkWell(
                       splashColor: Colors.blue.withAlpha(30),
                       onTap: () async{
                           //no action
                      },
                       child: Container(
                         padding: EdgeInsets.all(10.0),
                         width: double.infinity,
                         //height: 150,   //set to wrap
                           child:new Row(
                           children: <Widget>[


                         Container(
                              color: Colors.deepPurple[50],
                         padding: new EdgeInsets.all(5.0),
                         child: Text('$id', style: TextStyle(color: Colors.deepPurple, fontSize: 25.0, fontWeight: FontWeight.bold,),)
                         ),

                         SizedBox(width:15.0),

                         //add expanded to get full view area
                         Expanded(     
                           child: Column(
                             mainAxisSize: MainAxisSize.min,
                             crossAxisAlignment: CrossAxisAlignment.stretch,
                             children: <Widget>[

                               Row(
                                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: <Widget>[

                                      Text('$transfer', style: TextStyle(fontSize: 18.0, color: Colors.black54, letterSpacing: 1.5, ), overflow: TextOverflow.ellipsis,),
                                      Text("\u20B9 $amt", style: TextStyle(fontSize: 20.0, color: Colors.red, fontWeight: FontWeight.bold, ), overflow: TextOverflow.ellipsis,),
                                  ],
                               ),

                             ],
                           ),
                         ),

                         SizedBox(width:10.0),

                         VerticalDivider(thickness: 2.0, color: Colors.red,),

                           ],
                       ),
                       ),
                       ),
 );

how to achieve this expected output?

Thanks in advance.

2 Answers

You can wrap the Card within a container and add the following property:

decoration: BoxDecoration(
          border: Border(right: BorderSide(color: Colors.red,width: 3,)),
         ),

Your code will become something like this...

Container(
        decoration: BoxDecoration(
          border: Border(right: BorderSide(color: Colors.red,width: 3,)),
        ),
              child: Card(

          margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
          elevation: 2.0,
          child: InkWell(
            splashColor: Colors.blue.withAlpha(30),
            onTap: () async {
              //no action
            },
            child: Container(
              padding: EdgeInsets.all(10.0),
              width: double.infinity,
              //height: 150,   //set to wrap
              child: new Row(
                children: <Widget>[
                  Container(
                      color: Colors.deepPurple[50],
                      padding: new EdgeInsets.all(5.0),
                      child: Text(
                        'jdjjd',
                        style: TextStyle(
                          color: Colors.deepPurple,
                          fontSize: 25.0,
                          fontWeight: FontWeight.bold,
                        ),
                      )),

                  SizedBox(width: 15.0),

                  //add expanded to get full view area
                  Expanded(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: <Widget>[
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Text(
                              'transfer',
                              style: TextStyle(
                                fontSize: 18.0,
                                color: Colors.black54,
                                letterSpacing: 1.5,
                              ),
                              overflow: TextOverflow.ellipsis,
                            ),
                            Text(
                              "\u20B9",
                              style: TextStyle(
                                fontSize: 20.0,
                                color: Colors.red,
                                fontWeight: FontWeight.bold,
                              ),
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),

                  SizedBox(width: 10.0),

                  // VerticalDivider(
                  //   thickness: 2.0,
                  //   color: Colors.red,
                  // ),
                ],
              ),
            ),
          ),
        ),
      ),

Please not that I have removed the variables in the string for compilation purpose...

we have to use card with height and width defined, then we can fix verticalDivider() and Container(). container fits well in my case. thanks to previous answer which helped me arrive at expected result.

Lets Look at the Code:

Card(
    margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
    elevation: 2.0,
      child: InkWell(
                  splashColor: Colors.blue.withAlpha(30),
                  onTap: () async{
                      //no action
                 },
                  child: Container(
                    padding: EdgeInsets.fromLTRB(10,0,0,0),
                    width: double.infinity,
                    height: 60,       //75  //no wrap to set indicator at end
                      child:new Row(
                      children: <Widget>[


                    Container(
                         color: Colors.deepPurple[50],
                    padding: new EdgeInsets.all(5.0),
                    child: Text('$id', style: TextStyle(color: Colors.deepPurple, fontSize: 25.0, fontWeight: FontWeight.bold,),)
                    ),

                    SizedBox(width:15.0),

                    //add expanded to get full view area
                    Expanded(     
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: <Widget>[

                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                             children: <Widget>[

                                 Text('$transfer', style: TextStyle(fontSize: 18.0, color: Colors.black54, letterSpacing: 1.5, ), overflow: TextOverflow.ellipsis,),
                                 Text("\u20B9 $amt", style: TextStyle(fontSize: 20.0, color: uiColor, fontWeight: FontWeight.bold, ), overflow: TextOverflow.ellipsis,),
                             ],
                          ),

                        ],
                      ),
                    ),

                    SizedBox(width:20.0),

                    Container(
                      decoration: BoxDecoration(
                          border: Border(right: BorderSide(color: Colors.red,width: 3,)),
                        ),
                    ),

                      ],
                  ),
                  ),
                  ),
  );

this border will be shown only when your parent widget has defined height constraint. bcz both container and verticaldivider depends on height.

Final Output:

card with colored edge

Hope this will help someone !

Related