Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
B
Byodv2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
Byodv2
Commits
d5f52070
Commit
d5f52070
authored
Oct 11, 2022
by
Dio Maulana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mqtt to reload viewbill
parent
45828f6e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
1 deletion
+123
-1
mq.dart
lib/helper/mq.dart
+103
-0
new_home2.dart
lib/ui/home/new_home2.dart
+3
-1
splash.dart
lib/ui/splash.dart
+1
-0
view_bill.dart
lib/ui/viewbill/view_bill.dart
+1
-0
pubspec.lock
pubspec.lock
+14
-0
pubspec.yaml
pubspec.yaml
+1
-0
No files found.
lib/helper/mq.dart
0 → 100644
View file @
d5f52070
// ignore_for_file: unused_catch_clause
import
'dart:io'
;
import
'dart:js'
;
import
'package:byod/bloc/view_bill.dart'
;
import
'package:byod/helper/logger.dart'
;
import
'package:byod/main.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:mqtt_client/mqtt_browser_client.dart'
;
import
'package:mqtt_client/mqtt_client.dart'
;
import
'package:uuid/uuid.dart'
;
String
mqttUrl
=
'ws://mqtt.ravku.com'
;
final
mqClient
=
MqttBrowserClient
(
mqttUrl
,
''
);
const
int
mqttPort
=
1883
;
const
String
queueTopic
=
'romi/byod/payment'
;
// String queueMessage = getMqMessage();
const
String
usernameMq
=
'jasadigital'
;
const
String
passwordMq
=
'jasadigital'
;
const
uuidInit
=
Uuid
();
var
uuid
=
uuidInit
.
v4
();
Future
<
int
>
runMqTT
(
BuildContext
context
)
async
{
mqClient
.
logging
(
on:
false
);
mqClient
.
setProtocolV311
();
mqClient
.
keepAlivePeriod
=
86400
;
mqClient
.
port
=
mqttPort
;
mqClient
.
onDisconnected
;
mqClient
.
onConnected
;
mqClient
.
onSubscribed
;
// mqClient.pongCallback = pong;
final
connMess
=
MqttConnectMessage
()
.
withClientIdentifier
(
uuid
)
.
withWillTopic
(
'willtopic'
)
// If you set this you must set a will message
.
withWillMessage
(
'My Will message'
)
.
startClean
()
// Non persistent session for testing
.
withWillQos
(
MqttQos
.
atLeastOnce
);
// print('EXAMPLE::Mosquitto client connecting....');
mqClient
.
connectionMessage
=
connMess
;
try
{
await
mqClient
.
connect
();
}
on
NoConnectionException
catch
(
e
)
{
if
(
debug
)
{
logd
(
'MQ CONFIG::client exception'
,
'
$e
'
);
}
mqClient
.
disconnect
();
}
on
SocketException
catch
(
e
)
{
if
(
debug
)
{
logd
(
'MQ CONFIG::socket exception'
,
'
$e
'
);
}
mqClient
.
disconnect
();
}
if
(
mqClient
.
connectionStatus
!.
state
==
MqttConnectionState
.
connected
)
{
if
(
debug
)
{
logd
(
'CHECK CONNECTION'
,
'CONNECTED'
);
}
}
else
{
/// Use status here rather than state if you also want the broker return code.
// print(
// 'EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is ${mqClient.connectionStatus}');
mqClient
.
disconnect
();
exit
(-
1
);
}
/// Ok, lets try a subscription
// print('EXAMPLE::Subscribing to the queuetest/1 topic');
var
topic
=
queueTopic
;
// Not a wildcard topic
mqClient
.
subscribe
(
topic
,
MqttQos
.
atMostOnce
);
/// The client has a change notifier object(see the Observable class) which we then listen to to get
/// notifications of published updates to each subscribed topic.
mqClient
.
updates
!.
listen
((
List
<
MqttReceivedMessage
<
MqttMessage
?>>?
c
)
{
final
recMess
=
c
![
0
].
payload
as
MqttPublishMessage
;
final
pt
=
MqttPublishPayload
.
bytesToStringAsString
(
recMess
.
payload
.
message
);
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print('');
if
(
c
[
0
].
topic
==
topic
&&
pt
.
contains
(
"ORDER-ID"
))
{
// update bill disini
String
sessionID
=
prefs
.
getString
(
'sessionId'
)
??
''
;
if
(
sessionID
!=
''
&&
pt
.
contains
(
sessionID
))
{
context
.
read
<
ViewBillBloc
>().
getBill
();
}
if
(
debug
)
{
logd
(
'CHECK TOPIC'
,
'TOPIC MASUK::
${c[0].topic}
, MESSAGE::
$pt
'
);
}
}
else
{
if
(
debug
)
{
logd
(
'CHECK TOPIC'
,
'TOPIC TIDAK SAMA, YANG MASUK::
$topic
, MESSAGE::
$pt
'
);
}
}
});
// final builder = MqttClientPayloadBuilder();
// builder.addString('Hello from mqtt_client');
// mqClient.publishMessage(topic, MqttQos.exactlyOnce, builder.payload!);
return
0
;
}
lib/ui/home/new_home2.dart
View file @
d5f52070
...
...
@@ -18,6 +18,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import
'package:sliver_tools/sliver_tools.dart'
;
import
'../../bloc/filter_menu.dart'
;
import
'../../helper/mq.dart'
;
import
'../../helper/widget/button_dialog.dart'
;
import
'../../main.dart'
;
import
'../../models/fav_group.dart'
;
...
...
@@ -29,7 +30,6 @@ import 'cat_list.dart';
import
'fav_grid_menu.dart'
;
import
'fav_list.dart'
;
import
'package:byod/models/category_list.dart'
;
import
'shimmer_menu.dart'
;
import
'shimmer_menu_new.dart'
;
class
NewHome2
extends
StatefulWidget
{
...
...
@@ -107,6 +107,8 @@ class _NewHome2State extends State<NewHome2> {
// }
},
);
runMqTT
(
context
);
_scrollFavItem
.
addListener
(()
{
double
positionMenuFavScroll
=
_scrollFavItem
.
position
.
pixels
;
double
positionMenuFavMax
=
_scrollFavItem
.
position
.
maxScrollExtent
;
...
...
lib/ui/splash.dart
View file @
d5f52070
...
...
@@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'../bloc/branch_exist.dart'
;
import
'../helper/mq.dart'
;
import
'../main.dart'
;
import
'package:flutter/services.dart'
as
bundle_root
;
import
'home/new_home2.dart'
;
...
...
lib/ui/viewbill/view_bill.dart
View file @
d5f52070
...
...
@@ -23,6 +23,7 @@ import 'package:uuid/uuid.dart';
import
'../../api/api.dart'
;
import
'../../bloc/branch_exist.dart'
;
import
'../../bloc/feedback_option.dart'
;
import
'../../helper/mq.dart'
;
import
'../../helper/widget/button_dialog.dart'
;
import
'../../helper/widget/emoticon_rate.dart'
;
import
'../../helper/widget/open_url.dart'
;
...
...
pubspec.lock
View file @
d5f52070
...
...
@@ -71,6 +71,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
event_bus:
dependency: transitive
description:
name: event_bus
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
fake_async:
dependency: transitive
description:
...
...
@@ -205,6 +212,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
mqtt_client:
dependency: "direct main"
description:
name: mqtt_client
url: "https://pub.dartlang.org"
source: hosted
version: "9.7.2"
nested:
dependency: transitive
description:
...
...
pubspec.yaml
View file @
d5f52070
...
...
@@ -35,6 +35,7 @@ dependencies:
http
:
^0.13.4
intl
:
^0.17.0
loading_animations
:
^2.2.0
mqtt_client
:
^9.7.2
scrollable_positioned_list
:
^0.3.4
shared_preferences
:
^2.0.15
shimmer
:
^2.0.0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment