Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListView.builder(
- padding: EdgeInsets.only(top: 8.0, left: 15.0, right: 15.0),
- itemCount: messages.length,
- itemBuilder: (context, index) {
- return Container(
- padding: EdgeInsets.all(20.0),
- margin: index % 2 == 0
- ? EdgeInsets.only(bottom: 5.0, right: 60.0)
- : EdgeInsets.only(bottom: 5.0, left: 60.0),
- decoration: index % 2 == 0
- ? BoxDecoration(
- border: Border.all(
- color: Colors.grey,
- ),
- borderRadius: BorderRadius.all(
- Radius.circular(30.0),
- ),
- )
- : BoxDecoration(
- color: Colors.grey[300],
- borderRadius: BorderRadius.all(
- Radius.circular(30.0),
- ),
- ),
- child: Text(
- messages[index].text,
- style: TextStyle(color: Colors.black),
- ),
- );
- },
- ),
- ListView.builder(
- padding: EdgeInsets.only(top: 8.0, left: 15.0, right: 15.0),
- itemCount: messages.length,
- itemBuilder: (context, index) {
- return Align(
- alignment:
- index % 2 == 0 ? Alignment.centerLeft : Alignment.centerRight,
- child: UnconstrainedBox(
- child: Container(
- padding: EdgeInsets.all(20.0),
- decoration: index % 2 == 0
- ? BoxDecoration(
- border: Border.all(
- color: Colors.grey,
- ),
- borderRadius: BorderRadius.all(
- Radius.circular(30.0),
- ),
- )
- : BoxDecoration(
- color: Colors.grey[300],
- borderRadius: BorderRadius.all(
- Radius.circular(30.0),
- ),
- ),
- child: Text(
- messages[index].text,
- style: TextStyle(color: Colors.black),
- ),
- ),
- ),
- );
- },
- );
- @override
- Widget build(BuildContext context) {
- final messages = [
- 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
- 'This is a short message.',
- 'This is a relatively longer line of text.',
- 'Hi!'
- ];
- return Scaffold(
- body: ListView.builder(
- itemCount: messages.length,
- itemBuilder: (context, index) {
- return Padding(
- padding: const EdgeInsets.all(20.0),
- child: Flex(
- direction: Axis.horizontal,
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(10.0),
- constraints: BoxConstraints(
- maxWidth: MediaQuery.of(context).size.width * 0.7,
- ),
- decoration: BoxDecoration(
- border: Border.all(),
- borderRadius: BorderRadius.circular(10.0),
- ),
- child: Text(messages[index]),
- )
- ],
- ),
- );
- },
- ),
- );
- }
Add Comment
Please, Sign In to add comment