add drawer
This commit is contained in:
@@ -2,11 +2,17 @@ import 'package:example/advanced_options_page.dart';
|
|||||||
import 'package:example/main.dart';
|
import 'package:example/main.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import 'notifications_service.dart';
|
import 'notifications_service.dart';
|
||||||
|
|
||||||
|
const kStreamApiKey = 'STREAM_API_KEY';
|
||||||
|
const kStreamUserId = 'STREAM_USER_ID';
|
||||||
|
const kStreamToken = 'STREAM_TOKEN';
|
||||||
|
const kDefaultStreamApiKey = 's2dxdhpxd94g';
|
||||||
|
|
||||||
class ChooseUserPage extends StatelessWidget {
|
class ChooseUserPage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -116,6 +122,7 @@ class ChooseUserPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final secureStorage = FlutterSecureStorage();
|
||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
|
|
||||||
await client.setUser(
|
await client.setUser(
|
||||||
@@ -125,6 +132,21 @@ class ChooseUserPage extends StatelessWidget {
|
|||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
secureStorage.write(
|
||||||
|
key: kStreamApiKey,
|
||||||
|
value: kDefaultStreamApiKey,
|
||||||
|
),
|
||||||
|
secureStorage.write(
|
||||||
|
key: kStreamUserId,
|
||||||
|
value: user.id,
|
||||||
|
),
|
||||||
|
secureStorage.write(
|
||||||
|
key: kStreamToken,
|
||||||
|
value: token,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
initNotifications(client);
|
initNotifications(client);
|
||||||
}
|
}
|
||||||
|
|||||||
+100
-3
@@ -4,19 +4,34 @@ import 'package:example/choose_user_page.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import 'notifications_service.dart';
|
import 'notifications_service.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final secureStorage = FlutterSecureStorage();
|
||||||
|
|
||||||
|
final apiKey = await secureStorage.read(key: kStreamApiKey);
|
||||||
|
final userId = await secureStorage.read(key: kStreamUserId);
|
||||||
|
|
||||||
final client = Client(
|
final client = Client(
|
||||||
's2dxdhpxd94g',
|
apiKey ?? kDefaultStreamApiKey,
|
||||||
logLevel: Level.INFO,
|
logLevel: Level.INFO,
|
||||||
showLocalNotification:
|
showLocalNotification:
|
||||||
(!kIsWeb && Platform.isAndroid) ? showLocalNotification : null,
|
(!kIsWeb && Platform.isAndroid) ? showLocalNotification : null,
|
||||||
persistenceEnabled: true,
|
persistenceEnabled: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (userId != null) {
|
||||||
|
final token = await secureStorage.read(key: kStreamToken);
|
||||||
|
await client.setUser(
|
||||||
|
User(id: userId),
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
runApp(MyApp(client));
|
runApp(MyApp(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +53,7 @@ class MyApp extends StatelessWidget {
|
|||||||
client: client,
|
client: client,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
home: ChooseUserPage(),
|
home: client.state.user == null ? ChooseUserPage() : ChannelListPage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +61,89 @@ class MyApp extends StatelessWidget {
|
|||||||
class ChannelListPage extends StatelessWidget {
|
class ChannelListPage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final user = StreamChat.of(context).user;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
drawer: Drawer(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: MediaQuery.of(context).viewPadding.top + 8,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
bottom: 20.0,
|
||||||
|
left: 8,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
UserAvatar(
|
||||||
|
user: user,
|
||||||
|
showOnlineStatus: false,
|
||||||
|
constraints: BoxConstraints.tight(Size.fromRadius(20)),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 16.0),
|
||||||
|
child: Text(
|
||||||
|
user.name,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(StreamIcons.edit),
|
||||||
|
title: Text(
|
||||||
|
'New direct message',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(StreamIcons.group),
|
||||||
|
title: Text(
|
||||||
|
'New group',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: ListTile(
|
||||||
|
onTap: () async {
|
||||||
|
await StreamChat.of(context).client.disconnect();
|
||||||
|
|
||||||
|
final secureStorage = FlutterSecureStorage();
|
||||||
|
await secureStorage.deleteAll();
|
||||||
|
Navigator.pop(context);
|
||||||
|
await Navigator.pushReplacement(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ChooseUserPage(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
leading: Icon(StreamIcons.user),
|
||||||
|
title: Text(
|
||||||
|
'Sign out',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -60,7 +157,7 @@ class ChannelListPage extends StatelessWidget {
|
|||||||
swipeToAction: true,
|
swipeToAction: true,
|
||||||
filter: {
|
filter: {
|
||||||
'members': {
|
'members': {
|
||||||
'\$in': [StreamChat.of(context).user.id],
|
'\$in': [user.id],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: example
|
name: example
|
||||||
description: A new Flutter project.
|
description: A new Flutter project.
|
||||||
version: 1.0.47+49
|
version: 1.0.48+50
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.2.2 <3.0.0"
|
sdk: ">=2.2.2 <3.0.0"
|
||||||
@@ -13,6 +13,7 @@ dependencies:
|
|||||||
flutter_apns: ^1.3.1
|
flutter_apns: ^1.3.1
|
||||||
flutter_local_notifications: ^2.0.0
|
flutter_local_notifications: ^2.0.0
|
||||||
flutter_svg: ^0.19.1
|
flutter_svg: ^0.19.1
|
||||||
|
flutter_secure_storage: ^3.3.5
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@@ -482,6 +483,8 @@ class _ChannelListViewState extends State<ChannelListView>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamSubscription _subscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -506,7 +509,7 @@ class _ChannelListViewState extends State<ChannelListView>
|
|||||||
|
|
||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
|
|
||||||
client
|
_subscription = client
|
||||||
.on(
|
.on(
|
||||||
EventType.connectionRecovered,
|
EventType.connectionRecovered,
|
||||||
EventType.notificationAddedToChannel,
|
EventType.notificationAddedToChannel,
|
||||||
@@ -544,6 +547,7 @@ class _ChannelListViewState extends State<ChannelListView>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_subscription.cancel();
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user