Solution 1.
How to flutter image positioned center horizontally
Stack(
alignment: Alignment.center, // <---------
children: [
Text('Some text'),
// Other widgets
],
),
Stack(
alignment: Alignment.center,
children: <
Widget>[
Container(
height: displayHeight(context) * 0.24,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0)
]),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image(
height: displayHeight(context) * 0.08,
width: displayWidth(context) * 0.32,
image: NetworkImage(
widget.image != null
? 'https://' +
widget.image
: "Not Found",
),
fit: BoxFit.cover),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
child: Row(children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios),
iconSize: 30.0,
color: Colors.white,
onPressed: () => Navigator.pop(context)),
]),
),
Positioned(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15)),
),
child: Text(
widget.data.length > 20?widget.data.substring(0, 20)+ "..":widget.data,
style: TextStyle(
fontSize: displayWidth(context) * 0.070,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
]),
),
],
),
clik here for Refrence
Solution 2:
How to set backgroundcolor of text in flutter
new Container(
width: 100,
height: 30,
decoration: new BoxDecoration(
color: Colors.green
),
)
Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15)),
),
child: Text(
widget.data.length > 20?widget.data.substring(0, 20)+ "..":widget.data,
style: TextStyle(
fontSize: displayWidth(context) * 0.070,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Solution3
How to add substring range in Flutter if the word is less than the range
var text = 'simply dummy text for printing ';
Text(text.length > 12 ? text.substring(0, 12) : text,),
child: Text(
widget.data.length > 12?widget.data.substring(0, 12)+ "..":widget.data,
style: TextStyle(
fontSize: displayWidth(context) * 0.070,
color: Colors.black,
fontWeight: FontWeight.bold),
),
Top comments (0)