create a new app and client for advanced options
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
@@ -5,13 +7,24 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
import 'notifications_service.dart';
|
import 'notifications_service.dart';
|
||||||
|
|
||||||
class AdvancedOptionsPage extends StatelessWidget {
|
class AdvancedOptionsPage extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_AdvancedOptionsPageState createState() => _AdvancedOptionsPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
final TextEditingController _apiKeyController = TextEditingController();
|
final TextEditingController _apiKeyController = TextEditingController();
|
||||||
|
|
||||||
final TextEditingController _userIdController = TextEditingController();
|
final TextEditingController _userIdController = TextEditingController();
|
||||||
|
|
||||||
final TextEditingController _userTokenController = TextEditingController();
|
final TextEditingController _userTokenController = TextEditingController();
|
||||||
|
|
||||||
final TextEditingController _usernameController = TextEditingController();
|
final TextEditingController _usernameController = TextEditingController();
|
||||||
|
|
||||||
|
bool loading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -36,14 +49,15 @@ class AdvancedOptionsPage extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 16,
|
horizontal: 16,
|
||||||
vertical: 16,
|
vertical: 16,
|
||||||
),
|
),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
onChanged: () {},
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
@@ -159,38 +173,95 @@ class AdvancedOptionsPage extends StatelessWidget {
|
|||||||
borderRadius: BorderRadius.circular(26),
|
borderRadius: BorderRadius.circular(26),
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
if (loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loading = true;
|
||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
final apiKey = _apiKeyController.text;
|
final apiKey = _apiKeyController.text;
|
||||||
final userId = _userIdController.text;
|
final userId = _userIdController.text;
|
||||||
final userToken = _userTokenController.text;
|
final userToken = _userTokenController.text;
|
||||||
final username = _usernameController.text;
|
final username = _usernameController.text;
|
||||||
|
|
||||||
final client = StreamChat.of(context).client;
|
showDialog(
|
||||||
client.apiKey = apiKey;
|
barrierDismissible: false,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => Center(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
height: 100,
|
||||||
|
width: 100,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
print('CREATE CLIENT');
|
||||||
|
final client = Client(
|
||||||
|
apiKey,
|
||||||
|
logLevel: Level.INFO,
|
||||||
|
showLocalNotification:
|
||||||
|
(!kIsWeb && Platform.isAndroid)
|
||||||
|
? showLocalNotification
|
||||||
|
: null,
|
||||||
|
persistenceEnabled: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
await client.setUser(
|
await client.setUser(
|
||||||
User(id: userId, extraData: {
|
User(id: userId, extraData: {
|
||||||
'name': username,
|
'name': username,
|
||||||
}),
|
}),
|
||||||
userToken,
|
userToken,
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
var errorText = 'Error connecting, retry';
|
||||||
|
if (e is Map) {
|
||||||
|
errorText = e['message'] ?? errorText;
|
||||||
|
}
|
||||||
|
Navigator.pop(context);
|
||||||
|
Scaffold.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(errorText),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
loading = false;
|
||||||
|
await client.disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
initNotifications(client);
|
initNotifications(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
await Navigator.pushReplacement(
|
await Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
|
return MaterialApp(
|
||||||
|
theme: ThemeData.light(),
|
||||||
|
darkTheme: ThemeData.dark(),
|
||||||
|
//TODO change to system once dark theme is implemented
|
||||||
|
themeMode: ThemeMode.light,
|
||||||
|
builder: (context, widget) {
|
||||||
return StreamChat(
|
return StreamChat(
|
||||||
|
child: widget,
|
||||||
client: client,
|
client: client,
|
||||||
child: ChannelListPage(),
|
);
|
||||||
|
},
|
||||||
|
home: ChannelListPage(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -199,6 +270,8 @@ class AdvancedOptionsPage extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,24 @@ class ChooseUserPage extends StatelessWidget {
|
|||||||
final user = entry.value;
|
final user = entry.value;
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
showDialog(
|
||||||
|
barrierDismissible: false,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => Center(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
height: 100,
|
||||||
|
width: 100,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
|
|
||||||
await client.setUser(
|
await client.setUser(
|
||||||
@@ -111,6 +129,7 @@ class ChooseUserPage extends StatelessWidget {
|
|||||||
initNotifications(client);
|
initNotifications(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
await Navigator.pushReplacement(
|
await Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: example
|
name: example
|
||||||
description: A new Flutter project.
|
description: A new Flutter project.
|
||||||
|
|
||||||
version: 1.0.45+47
|
version: 1.0.46+48
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.2.2 <3.0.0"
|
sdk: ">=2.2.2 <3.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user