Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'func.dart';
- class Message {
- Message(this.text, this.isMe);
- String text;
- bool isMe;
- }
- class Bubble extends StatelessWidget {
- Bubble({this.message, this.isMe});
- final String message;
- final bool isMe;
- @override
- Widget build(BuildContext context) {
- final bg = isMe ? Colors.lightBlue : Colors.greenAccent.shade200;
- final align = isMe ? CrossAxisAlignment.start : CrossAxisAlignment.end;
- final radius = BorderRadius.only(
- topRight: Radius.circular(isMe ? 5.0 : 0),
- topLeft: Radius.circular(isMe ? 0 : 5.0),
- bottomLeft: Radius.circular(isMe ? 10.0 : 5.0),
- bottomRight: Radius.circular(5.0),
- );
- return Column(
- crossAxisAlignment: align,
- children: <Widget>[
- Container(
- margin: const EdgeInsets.all(3.0),
- padding: const EdgeInsets.all(8.0),
- decoration: BoxDecoration(
- color: bg,
- borderRadius: radius,
- ),
- child: Stack(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(right: 48.0),
- child: Text(
- message,
- style: TextStyle(
- fontSize: 20.0,
- ),
- )),
- ],
- ))
- ],
- );
- }
- }
- class Dialogue extends StatelessWidget {
- Dialogue({this.messages});
- final Stream<Message> messages;
- @override
- Widget build(BuildContext context) {
- return StreamBuilder(
- stream: aggregate(messages),
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- if (snapshot.hasError) {
- return Text("Dialogue stream failure :(");
- } else {
- final msgs = snapshot.data as List<Message>;
- return Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: msgs
- .map((msg) => Bubble(
- message: msg.text,
- isMe: msg.isMe,
- ))
- .toList());
- }
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement