CHATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

This commit is contained in:
Carlos Lopez-Rosario
2020-05-03 03:25:59 -04:00
parent 203bb03464
commit 68460c8b20
6 changed files with 376 additions and 21 deletions

View File

@@ -12,4 +12,4 @@ class App extends StatelessWidget {
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
}

View File

@@ -173,7 +173,7 @@ class EasyAccess extends StatelessWidget {
onTap: () => {
print("Tapped $label"),
if(label == 'Chat'){
Navigator.pushNamed(context, '/Chat', arguments: gameCard.sportTitle)
Navigator.pushNamed(context, '/Chat', arguments: [gameCard.sportTitle, gameCard.idSport])
}
},
);

View File

@@ -1,19 +1,101 @@
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
class Chat extends StatelessWidget{
String sport;
class _Chat {
final client = Client(
'xqf4gbfwu2ec',
logLevel: Level.INFO,
);
Future<Client> init() async {
await client.setGuestUser(
User(id: 'You'
),
);
final user = User(id: "carlos", extraData: {
"name": "John Doe",
});
await client.setUser(
user,
client.devToken("carlos"),
);
return client;
}
}
class Chat extends StatelessWidget {
final List sport;
Chat(this.sport);
@override
Widget build(BuildContext context) {
return StatefulBuilder(
builder: (context, StateSetter setState) => Scaffold(
appBar: AppBar(
centerTitle: false,
title: Text('$sport Chat'),
backgroundColor: Colors.green,
_Chat c = _Chat();
var x = c.init();
return Scaffold(
appBar: AppBar(
centerTitle: false,
title: Text('${sport[0]} Chat'),
backgroundColor: Colors.green,
),
body: FutureBuilder(
future: x,
builder: (context, snapshot){
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else {
return ContainerWithInterceptor(snapshot.data, sport[1]);
}
},
),
);
}
}
class ChannelPage extends StatelessWidget {
const ChannelPage({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: MessageListView(
// messageBuilder: _messageBuilder,
),
),
body: Center(child: Text("Chat Goes Here")),
));
MessageInput(),
],
);
}
}
class ContainerWithInterceptor extends StatefulWidget {
final Client client;
final int sport;
ContainerWithInterceptor(this.client, this.sport);
@override
State createState() => _ContainerWithInterceptorState();
}
class _ContainerWithInterceptorState extends State<ContainerWithInterceptor> {
Widget build(BuildContext context) {
var cc = widget.client.channel("messaging", id: "${widget.sport}");
print(widget.sport);
print("-------------------------------------------------------------");
cc.watch();
return StreamChat(
client: widget.client,
child: StreamChannel(
channel: cc,
child: ChannelPage(),
),
);
}
}

View File

@@ -105,7 +105,7 @@ class Sport extends StatelessWidget {
ListTile(
title: IconButton(
icon: Icon(Icons.message),
onPressed: () => Navigator.pushNamed(context, '/Chat',arguments: _curSport.name),
onPressed: () => Navigator.pushNamed(context, '/Chat',arguments: [sport_ID, _curSport.name]),
),
)
],