Skip to content

Commit

Permalink
updated code for sample app, added some button replacement for web.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetRanjan308 committed Apr 16, 2024
1 parent 5025e7c commit 8db74d9
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 13 deletions.
243 changes: 231 additions & 12 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:kommunicate_flutter/kommunicate_flutter.dart';
Expand Down Expand Up @@ -47,6 +48,8 @@ class HomePageWidget extends StatelessWidget {
return "Android";
} else if (Platform.isIOS) {
return "iOS";
} else if (kIsWeb) {
return "Web";
} else {
return "NOP";
}
Expand Down Expand Up @@ -110,16 +113,114 @@ class HomePageWidget extends StatelessWidget {
});
}

String coversationIDValue = '';
Future<void> _displayConversationIDInputDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Conversation ID'),
content: TextField(
onChanged: (value) {
coversationIDValue = value;
print(value);
},
decoration: InputDecoration(hintText: "Enter Conversation ID"),
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
child: Text('CANCEL'),
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
onPressed: () {
KommunicateFlutterPlugin.openParticularConversation(coversationIDValue);
Navigator.pop(context);
},
child: Text('OK'),
),
],
);
});
}

String messageText = '';
Future<void> _displayMessageInputDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Enter Message and Conversation ID'),
content: SizedBox(
height: MediaQuery.of(context).size.height * 0.2, // Set the height to 30% of the screen height
child: SingleChildScrollView(
child: Column(
children: [
TextField(
onChanged: (value) {
coversationIDValue = value;
print(value);
},
decoration: InputDecoration(hintText: "Enter Conversation ID"),
),
SizedBox(height: 10),
TextField(
onChanged: (value) {
messageText = value;
print(value);
},
decoration: InputDecoration(hintText: "Enter Message"),
),
],
),
),
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
child: Text('CANCEL'),
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
onPressed: () {
KommunicateFlutterPlugin.sendMessage({
"channelID": "$coversationIDValue",
"message": "$messageText"
});
Navigator.pop(context);
},
child: Text('OK'),
),
],
);
},
);
}


@override
Widget build(BuildContext context) {
return Center(
child: Container(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Material(
List<Widget> widgets = [
new Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff5c5aa7),
Expand All @@ -141,8 +242,9 @@ class HomePageWidget extends StatelessWidget {
color: Color(0xff5c5aa7),
child: new MaterialButton(
onPressed: () {
KommunicateFlutterPlugin.openParticularConversation(
'46286348');
// KommunicateFlutterPlugin.openParticularConversation(
// '46286348');
_displayConversationIDInputDialog(context);
},
minWidth: 400,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
Expand Down Expand Up @@ -267,8 +369,125 @@ class HomePageWidget extends StatelessWidget {
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.bold)),
))
],
)),
];

if (kIsWeb) {
widgets.removeRange(widgets.length - 9, widgets.length - 1);
widgets.insert(
widgets.length - 1, // Insert before the logout button
new Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff5c5aa7),
child: new MaterialButton(
onPressed: () {
KommunicateFlutterPlugin.buildConversation({})
.then((result) {
print("Conversation builder success : " + result.toString());
}).catchError((error) {
print("Conversation builder error occurred : " + error.toString());
});
},
minWidth: 400,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
child: Text(
"Build Conversation",
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'Montserrat', fontSize: 20.0)
.copyWith(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
);
widgets.insert(
widgets.length - 1,
SizedBox(height: 10),
);
widgets.insert(
widgets.length - 1, // Insert before the logout button
new Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff5c5aa7),
child: new MaterialButton(
onPressed: () {
_displayMessageInputDialog(context);
},
minWidth: 400,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
child: Text(
"Send Message",
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'Montserrat', fontSize: 20.0)
.copyWith(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
);
widgets.insert(
widgets.length - 1,
SizedBox(height: 10),
);
widgets.insert(
widgets.length - 1, // Insert before the logout button
new Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff5c5aa7),
child: new MaterialButton(
onPressed: () {
KommunicateFlutterPlugin.isChatWidgetVisible(false);
},
minWidth: 400,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
child: Text(
"Hide Chat Widget",
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'Montserrat', fontSize: 20.0)
.copyWith(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
);
widgets.insert(
widgets.length - 1,
SizedBox(height: 10),
);
widgets.insert(
widgets.length - 1, // Insert before the logout button
new Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Color(0xff5c5aa7),
child: new MaterialButton(
onPressed: () {
KommunicateFlutterPlugin.isChatWidgetVisible(true);
},
minWidth: 400,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
child: Text(
"Show Widget",
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'Montserrat', fontSize: 20.0)
.copyWith(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
);
widgets.insert(
widgets.length - 1,
SizedBox(height: 10),
);
}

return Center(
child: Container(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: widgets,
),
),
);
Expand Down
5 changes: 4 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:kommunicate_flutter/kommunicate_flutter.dart';
import 'AppConfig.dart';
import 'prechat.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

import 'home.dart';

Expand All @@ -21,6 +22,7 @@ MethodChannel channel = MethodChannel('kommunicate_flutter');
class _MyAppState extends State<MyApp> {
@override
void initState() {
if (kIsWeb == false) {
channel.setMethodCallHandler((call){
if(call.method == 'onPluginLaunch'){
print(call.arguments);
Expand All @@ -39,6 +41,7 @@ class _MyAppState extends State<MyApp> {
}
return Future.value(null);
});
}
super.initState();
}

Expand Down Expand Up @@ -72,7 +75,7 @@ class LoginPage extends StatelessWidget {
'userId': userId.text,
'password': password.text,
'appId': AppConfig.APP_ID,
'contactNumber': "31213124124"
'authenticationTypeId': 1
};

KommunicateFlutterPlugin.login(user).then((result) {
Expand Down

0 comments on commit 8db74d9

Please sign in to comment.