Commit 123b7f72 authored by valdi's avatar valdi

fix size

parent 97c154c2
{
"baseUrl" : "http://192.168.2.142:8000/"
"base_url" : "http://192.168.2.142:8000/"
}
\ No newline at end of file
import 'package:manager_queue/main.dart';
import 'package:mqtt_client/mqtt_browser_client.dart';
import 'dart:convert';
const String baseUrl = "http://192.168.2.142:8000/";
const String apiUrlQueue = baseUrl + "api/getqueue";
const String apiUrlUpdate = baseUrl + "api/updatequeue";
const String apiUrlClear = baseUrl + "api/clearqueue";
final String? baseUrls = prefs.getString('base_url');
final String? mqqtIdentifiers = prefs.getString('uuid');
final String mqqtIdentifier = mqqtIdentifiers!;
final String baseUrl = baseUrls!;
final String apiUrlQueue = baseUrl + "api/getqueue";
final String apiUrlUpdate = baseUrl + "api/updatequeue";
final String apiUrlClear = baseUrl + "api/clearqueue";
const String mqttUrl = "ws://dev.ravku.com";
const String queueTopic = "queuetest/1";
const String queueMessage = "updateApi";
......
......@@ -9,109 +9,130 @@ import 'package:manager_queue/cubit/ready_cubit.dart';
import 'package:manager_queue/helper/config.dart';
import 'package:manager_queue/main_page.dart';
import 'package:manager_queue/splash.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'bloc/selected_queue_bloc.dart';
import 'bloc/selected_ready_bloc.dart';
void main() {
// var prefs = await SharedPreferences.getInstance();
late SharedPreferences prefs;
void main() async {
prefs = await SharedPreferences.getInstance();
runApp(MyApp());
}
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;
// 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('Mqtt_MyClientUniqueId')
.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;
// final connMess = MqttConnectMessage()
// .withClientIdentifier('Mqtt_MyClientUniqueId')
// .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) {
// Raised by the client when connection fails.
// print('EXAMPLE::client exception - $e');
mqClient.disconnect();
} on SocketException catch (e) {
// Raised by the socket layer
// print('EXAMPLE::socket exception - $e');
mqClient.disconnect();
}
if (mqClient.connectionStatus!.state == MqttConnectionState.connected) {
// print('EXAMPLE::Mosquitto client 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);
}
// try {
// await mqClient.connect();
// } on NoConnectionException catch (e) {
// // Raised by the client when connection fails.
// // print('EXAMPLE::client exception - $e');
// mqClient.disconnect();
// } on SocketException catch (e) {
// // Raised by the socket layer
// // print('EXAMPLE::socket exception - $e');
// mqClient.disconnect();
// }
// if (mqClient.connectionStatus!.state == MqttConnectionState.connected) {
// // print('EXAMPLE::Mosquitto client 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);
// /// 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);
// // if (c[0].topic == topic && pt == queueMessage) {
// // context.read<QueueBloc>().queueList();
// // // print("berhasil update API");
// // } else {
// // // print("tidak berhasil dapat message yang sesuai");
// // }
// /// 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);
// // // if (c[0].topic == topic && pt == queueMessage) {
// // // context.read<QueueBloc>().queueList();
// // // // print("berhasil update API");
// // // } else {
// // // // print("tidak berhasil dapat message yang sesuai");
// // // }
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print('');
// });
// print('EXAMPLE::Sleeping....');
// await MqttUtilities.asyncSleep(60);
// // print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// // print('');
// // });
// // print('EXAMPLE::Sleeping....');
// // await MqttUtilities.asyncSleep(60);
// /// Finally, unsubscribe and exit gracefully
// print('EXAMPLE::Unsubscribing');
// mqClient.unsubscribe(topic);
// // /// Finally, unsubscribe and exit gracefully
// // print('EXAMPLE::Unsubscribing');
// // mqClient.unsubscribe(topic);
/// Wait for the unsubscribe message from the broker if you wish.
// await MqttUtilities.asyncSleep(2);
// print('EXAMPLE::Disconnecting');
// mqClient.disconnect();
return 0;
}
// /// Wait for the unsubscribe message from the broker if you wish.
// // await MqttUtilities.asyncSleep(2);
// // print('EXAMPLE::Disconnecting');
// // mqClient.disconnect();
// return 0;
// }
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
runMqTT(context);
return MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => MultiBlocProvider(providers: [
// runMqTT(context);
// return MaterialApp(
// initialRoute: '/',
// routes: {
// '/': (context) => MultiBlocProvider(providers: [
// BlocProvider(create: (_) => QueueBloc()),
// BlocProvider(create: (_) => ReadyBloc()),
// BlocProvider(create: (_) => SelectedQueueBloc()),
// BlocProvider(create: (_) => QueueCubit()),
// BlocProvider(create: (_) => SelectedReadyBloc()),
// BlocProvider(create: (_) => ReadyCubit()),
// ], child: MainPage()),
// },
// debugShowCheckedModeBanner: false,
// );
return MultiBlocProvider(
providers: [
BlocProvider(create: (_) => QueueBloc()),
BlocProvider(create: (_) => ReadyBloc()),
BlocProvider(create: (_) => SelectedQueueBloc()),
BlocProvider(create: (_) => QueueCubit()),
BlocProvider(create: (_) => SelectedReadyBloc()),
BlocProvider(create: (_) => ReadyCubit()),
], child: MainPage()),
},
// BlocProvider(create: (_) => StylingBloc()),
],
child: Builder(builder: (BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
// theme: ThemeData(brightness: Brightness.dark),
initialRoute: '/',
routes: {'/': (context) => Splash()},
);
}),
);
}
}
......@@ -132,19 +132,20 @@ class _MainPageState extends State<MainPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 1000,
height: 100,
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightBlue,
alignment: Alignment.center,
child: Text(
"QUEUE",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700),
fontSize: MediaQuery.of(context).size.height * 0.03,
fontWeight: FontWeight.w700),
),
),
Container(
width: 700,
height: 700,
width: MediaQuery.of(context).size.width * 0.38,
height: MediaQuery.of(context).size.height * 0.75,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
......@@ -218,7 +219,7 @@ class _MainPageState extends State<MainPage> {
},
child: Card(
color: thisQueue.isSelected
? Colors.blue
? Colors.lightGreen
: Colors.black38,
shape: RoundedRectangleBorder(
borderRadius:
......@@ -245,8 +246,8 @@ class _MainPageState extends State<MainPage> {
setToReady(queueSelected);
},
child: Container(
width: 800,
height: 100,
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightBlue,
alignment: Alignment.center,
child: InkWell(
......@@ -266,9 +267,11 @@ class _MainPageState extends State<MainPage> {
Flexible(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.2,
height: MediaQuery.of(context).size.height * 1,
color: Colors.blueGrey,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Container(
// width: 400,
......@@ -310,14 +313,14 @@ class _MainPageState extends State<MainPage> {
);
},
child: Container(
width: 400,
height: 80,
width: MediaQuery.of(context).size.width * 0.18,
height: MediaQuery.of(context).size.height * 0.07,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
color: Colors.amber,
color: Colors.red,
),
alignment: Alignment.center,
child: Text(
......@@ -339,9 +342,9 @@ class _MainPageState extends State<MainPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 1000,
height: 100,
color: Colors.green,
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightGreen,
alignment: Alignment.center,
child: Text(
"READY",
......@@ -350,8 +353,8 @@ class _MainPageState extends State<MainPage> {
),
),
Container(
width: 700,
height: 700,
width: MediaQuery.of(context).size.width * 0.38,
height: MediaQuery.of(context).size.height * 0.75,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
......@@ -504,8 +507,9 @@ class _MainPageState extends State<MainPage> {
setToQueue(readySelected);
},
child: Container(
height: 100,
color: Colors.green,
width: MediaQuery.of(context).size.width * 0.2,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightGreen,
alignment: Alignment.center,
child: InkWell(
onTap: () => setToQueue(readySelected),
......@@ -526,7 +530,8 @@ class _MainPageState extends State<MainPage> {
setToPickUp(readySelected);
},
child: Container(
height: 100,
width: MediaQuery.of(context).size.width * 0.2,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.black26,
alignment: Alignment.center,
child: InkWell(
......
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:loading_animations/loading_animations.dart';
import 'package:manager_queue/models/queue.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:manager_queue/api.dart';
import 'package:manager_queue/bloc/queue_bloc.dart';
import 'package:manager_queue/helper/config.dart';
import 'package:manager_queue/main.dart';
import 'package:manager_queue/helper/config.dart';
import 'package:manager_queue/main_page.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter/services.dart' as bundel_root;
import 'package:http/http.dart' as http;
class Splash extends StatefulWidget {
const Splash({Key? key}) : super(key: key);
@override
State<Splash> createState() => _SplashState();
}
class _SplashState extends State<Splash> {
Future<String> loadBaseUrl() async {
String data = await bundel_root.rootBundle.loadString('baseurl.json');
return jsonDecode(data)['base_url'].toString();
}
Future<int> runMqTT() 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(mqqtIdentifier)
.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) {
// Raised by the client when connection fails.
// print('EXAMPLE::client exception - $e');
mqClient.disconnect();
} on SocketException catch (e) {
// Raised by the socket layer
// print('EXAMPLE::socket exception - $e');
mqClient.disconnect();
}
if (mqClient.connectionStatus!.state == MqttConnectionState.connected) {
// print('EXAMPLE::Mosquitto client 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);
if (c[0].topic == topic && pt == queueMessage) {
context.read<QueueBloc>().queueList();
// print("berhasil update API");
} else {
// print("tidak berhasil dapat message yang sesuai");
}
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print('');
});
return 0;
}
var uuidUnique = const Uuid();
@override
void initState() {
loadBaseUrl().then((value) async {
await prefs.setString('base_url', value);
await prefs.setString('uuid', uuidUnique.v4());
runMqTT();
Future.delayed(const Duration(seconds: 3), () {
Navigator.push(context, MaterialPageRoute(builder: (_) => MainPage()));
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Please wait",
style: TextStyle(
fontSize: MediaQuery.of(context).size.height * 0.03,
fontWeight: FontWeight.w500,
color: Colors.black,
decoration: TextDecoration.none),
),
LoadingBumpingLine.circle(
size: MediaQuery.of(context).size.height * 0.1,
backgroundColor: Colors.black,
)
],
);
}
}
......@@ -156,6 +156,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
loading_animations:
dependency: "direct main"
description:
name: loading_animations
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
matcher:
dependency: transitive
description:
......
......@@ -37,6 +37,7 @@ dependencies:
multi_select_flutter: ^4.0.0
shared_preferences: ^2.0.13
uuid: ^3.0.6
loading_animations: ^2.2.0
dev_dependencies:
......@@ -48,8 +49,8 @@ dev_dependencies:
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# assets:
# - assets/baseurl.json
assets:
- assets/baseurl.json
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment