Guest User

Untitled

a guest
Oct 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. ListView.builder(
  2. padding: EdgeInsets.only(top: 8.0, left: 15.0, right: 15.0),
  3. itemCount: messages.length,
  4. itemBuilder: (context, index) {
  5. return Container(
  6. padding: EdgeInsets.all(20.0),
  7. margin: index % 2 == 0
  8. ? EdgeInsets.only(bottom: 5.0, right: 60.0)
  9. : EdgeInsets.only(bottom: 5.0, left: 60.0),
  10. decoration: index % 2 == 0
  11. ? BoxDecoration(
  12. border: Border.all(
  13. color: Colors.grey,
  14. ),
  15. borderRadius: BorderRadius.all(
  16. Radius.circular(30.0),
  17. ),
  18. )
  19. : BoxDecoration(
  20. color: Colors.grey[300],
  21. borderRadius: BorderRadius.all(
  22. Radius.circular(30.0),
  23. ),
  24. ),
  25. child: Text(
  26. messages[index].text,
  27. style: TextStyle(color: Colors.black),
  28. ),
  29. );
  30. },
  31. ),
  32.  
  33. ListView.builder(
  34. padding: EdgeInsets.only(top: 8.0, left: 15.0, right: 15.0),
  35. itemCount: messages.length,
  36. itemBuilder: (context, index) {
  37. return Align(
  38. alignment:
  39. index % 2 == 0 ? Alignment.centerLeft : Alignment.centerRight,
  40. child: UnconstrainedBox(
  41. child: Container(
  42. padding: EdgeInsets.all(20.0),
  43. decoration: index % 2 == 0
  44. ? BoxDecoration(
  45. border: Border.all(
  46. color: Colors.grey,
  47. ),
  48. borderRadius: BorderRadius.all(
  49. Radius.circular(30.0),
  50. ),
  51. )
  52. : BoxDecoration(
  53. color: Colors.grey[300],
  54. borderRadius: BorderRadius.all(
  55. Radius.circular(30.0),
  56. ),
  57. ),
  58. child: Text(
  59. messages[index].text,
  60. style: TextStyle(color: Colors.black),
  61. ),
  62. ),
  63. ),
  64. );
  65. },
  66. );
  67.  
  68. @override
  69. Widget build(BuildContext context) {
  70. final messages = [
  71. 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
  72. 'This is a short message.',
  73. 'This is a relatively longer line of text.',
  74. 'Hi!'
  75. ];
  76. return Scaffold(
  77. body: ListView.builder(
  78. itemCount: messages.length,
  79. itemBuilder: (context, index) {
  80. return Padding(
  81. padding: const EdgeInsets.all(20.0),
  82. child: Flex(
  83. direction: Axis.horizontal,
  84. children: <Widget>[
  85. Container(
  86. padding: const EdgeInsets.all(10.0),
  87. constraints: BoxConstraints(
  88. maxWidth: MediaQuery.of(context).size.width * 0.7,
  89. ),
  90. decoration: BoxDecoration(
  91. border: Border.all(),
  92. borderRadius: BorderRadius.circular(10.0),
  93. ),
  94. child: Text(messages[index]),
  95. )
  96. ],
  97. ),
  98. );
  99. },
  100. ),
  101. );
  102. }
Add Comment
Please, Sign In to add comment