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 'package:mqtt_client/mqtt_browser_client.dart';
import 'dart:convert';
const String baseUrl = "http://192.168.2.142:8000/"; final String? baseUrls = prefs.getString('base_url');
const String apiUrlQueue = baseUrl + "api/getqueue"; final String? mqqtIdentifiers = prefs.getString('uuid');
const String apiUrlUpdate = baseUrl + "api/updatequeue"; final String mqqtIdentifier = mqqtIdentifiers!;
const String apiUrlClear = baseUrl + "api/clearqueue"; 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 mqttUrl = "ws://dev.ravku.com";
const String queueTopic = "queuetest/1"; const String queueTopic = "queuetest/1";
const String queueMessage = "updateApi"; const String queueMessage = "updateApi";
......
...@@ -9,109 +9,130 @@ import 'package:manager_queue/cubit/ready_cubit.dart'; ...@@ -9,109 +9,130 @@ import 'package:manager_queue/cubit/ready_cubit.dart';
import 'package:manager_queue/helper/config.dart'; import 'package:manager_queue/helper/config.dart';
import 'package:manager_queue/main_page.dart'; import 'package:manager_queue/main_page.dart';
import 'package:manager_queue/splash.dart';
import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_client.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'bloc/selected_queue_bloc.dart'; import 'bloc/selected_queue_bloc.dart';
import 'bloc/selected_ready_bloc.dart'; import 'bloc/selected_ready_bloc.dart';
void main() { late SharedPreferences prefs;
// var prefs = await SharedPreferences.getInstance(); void main() async {
prefs = await SharedPreferences.getInstance();
runApp(MyApp()); runApp(MyApp());
} }
Future<int> runMqTT(BuildContext context) async { // Future<int> runMqTT(BuildContext context) async {
mqClient.logging(on: false); // mqClient.logging(on: false);
mqClient.setProtocolV311(); // mqClient.setProtocolV311();
mqClient.keepAlivePeriod = 86400; // mqClient.keepAlivePeriod = 86400;
mqClient.port = mqttPort; // mqClient.port = mqttPort;
mqClient.onDisconnected; // mqClient.onDisconnected;
mqClient.onConnected; // mqClient.onConnected;
mqClient.onSubscribed; // mqClient.onSubscribed;
// mqClient.pongCallback = pong; // // mqClient.pongCallback = pong;
final connMess = MqttConnectMessage() // final connMess = MqttConnectMessage()
.withClientIdentifier('Mqtt_MyClientUniqueId') // .withClientIdentifier('Mqtt_MyClientUniqueId')
.withWillTopic('willtopic') // If you set this you must set a will message // .withWillTopic('willtopic') // If you set this you must set a will message
.withWillMessage('My Will message') // .withWillMessage('My Will message')
.startClean() // Non persistent session for testing // .startClean() // Non persistent session for testing
.withWillQos(MqttQos.atLeastOnce); // .withWillQos(MqttQos.atLeastOnce);
// print('EXAMPLE::Mosquitto client connecting....'); // // print('EXAMPLE::Mosquitto client connecting....');
mqClient.connectionMessage = connMess; // mqClient.connectionMessage = connMess;
try { // try {
await mqClient.connect(); // await mqClient.connect();
} on NoConnectionException catch (e) { // } on NoConnectionException catch (e) {
// Raised by the client when connection fails. // // Raised by the client when connection fails.
// print('EXAMPLE::client exception - $e'); // // print('EXAMPLE::client exception - $e');
mqClient.disconnect(); // mqClient.disconnect();
} on SocketException catch (e) { // } on SocketException catch (e) {
// Raised by the socket layer // // Raised by the socket layer
// print('EXAMPLE::socket exception - $e'); // // print('EXAMPLE::socket exception - $e');
mqClient.disconnect(); // mqClient.disconnect();
} // }
if (mqClient.connectionStatus!.state == MqttConnectionState.connected) { // if (mqClient.connectionStatus!.state == MqttConnectionState.connected) {
// print('EXAMPLE::Mosquitto client connected'); // // print('EXAMPLE::Mosquitto client connected');
} else { // } else {
/// Use status here rather than state if you also want the broker return code. // /// Use status here rather than state if you also want the broker return code.
// print( // // print(
// 'EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is ${mqClient.connectionStatus}'); // // 'EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is ${mqClient.connectionStatus}');
mqClient.disconnect(); // mqClient.disconnect();
exit(-1); // exit(-1);
} // }
/// Ok, lets try a subscription // /// Ok, lets try a subscription
// print('EXAMPLE::Subscribing to the queuetest/1 topic'); // // print('EXAMPLE::Subscribing to the queuetest/1 topic');
var topic = queueTopic; // Not a wildcard topic // var topic = queueTopic; // Not a wildcard topic
mqClient.subscribe(topic, MqttQos.atMostOnce); // mqClient.subscribe(topic, MqttQos.atMostOnce);
/// The client has a change notifier object(see the Observable class) which we then listen to to get // /// 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. // /// notifications of published updates to each subscribed topic.
// mqClient.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) { // // mqClient.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
// final recMess = c![0].payload as MqttPublishMessage; // // final recMess = c![0].payload as MqttPublishMessage;
// final pt = // // final pt =
// MqttPublishPayload.bytesToStringAsString(recMess.payload.message); // // MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
// // if (c[0].topic == topic && pt == queueMessage) { // // // if (c[0].topic == topic && pt == queueMessage) {
// // context.read<QueueBloc>().queueList(); // // // context.read<QueueBloc>().queueList();
// // // print("berhasil update API"); // // // // print("berhasil update API");
// // } else { // // // } else {
// // // print("tidak berhasil dapat message yang sesuai"); // // // // print("tidak berhasil dapat message yang sesuai");
// // } // // // }
// print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt '); // // print('Notifikasi masuk dari topic <${c[0].topic}>, isinya adalah: $pt ');
// print(''); // // print('');
// }); // // });
// print('EXAMPLE::Sleeping....'); // // print('EXAMPLE::Sleeping....');
// await MqttUtilities.asyncSleep(60); // // await MqttUtilities.asyncSleep(60);
// /// Finally, unsubscribe and exit gracefully // // /// Finally, unsubscribe and exit gracefully
// print('EXAMPLE::Unsubscribing'); // // print('EXAMPLE::Unsubscribing');
// mqClient.unsubscribe(topic); // // mqClient.unsubscribe(topic);
/// Wait for the unsubscribe message from the broker if you wish. // /// Wait for the unsubscribe message from the broker if you wish.
// await MqttUtilities.asyncSleep(2); // // await MqttUtilities.asyncSleep(2);
// print('EXAMPLE::Disconnecting'); // // print('EXAMPLE::Disconnecting');
// mqClient.disconnect(); // // mqClient.disconnect();
return 0; // return 0;
} // }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
runMqTT(context); // runMqTT(context);
return MaterialApp( // return MaterialApp(
initialRoute: '/', // initialRoute: '/',
routes: { // routes: {
'/': (context) => MultiBlocProvider(providers: [ // '/': (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: (_) => QueueBloc()),
BlocProvider(create: (_) => ReadyBloc()), BlocProvider(create: (_) => ReadyBloc()),
BlocProvider(create: (_) => SelectedQueueBloc()), BlocProvider(create: (_) => SelectedQueueBloc()),
BlocProvider(create: (_) => QueueCubit()), BlocProvider(create: (_) => QueueCubit()),
BlocProvider(create: (_) => SelectedReadyBloc()), BlocProvider(create: (_) => SelectedReadyBloc()),
BlocProvider(create: (_) => ReadyCubit()), BlocProvider(create: (_) => ReadyCubit()),
], child: MainPage()), // BlocProvider(create: (_) => StylingBloc()),
}, ],
child: Builder(builder: (BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
// theme: ThemeData(brightness: Brightness.dark),
initialRoute: '/',
routes: {'/': (context) => Splash()},
);
}),
); );
} }
} }
...@@ -132,19 +132,20 @@ class _MainPageState extends State<MainPage> { ...@@ -132,19 +132,20 @@ class _MainPageState extends State<MainPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Container( Container(
width: 1000, width: MediaQuery.of(context).size.width * 0.4,
height: 100, height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightBlue, color: Colors.lightBlue,
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
"QUEUE", "QUEUE",
style: TextStyle( style: TextStyle(
fontSize: 30, fontWeight: FontWeight.w700), fontSize: MediaQuery.of(context).size.height * 0.03,
fontWeight: FontWeight.w700),
), ),
), ),
Container( Container(
width: 700, width: MediaQuery.of(context).size.width * 0.38,
height: 700, height: MediaQuery.of(context).size.height * 0.75,
child: MediaQuery.removePadding( child: MediaQuery.removePadding(
context: context, context: context,
removeTop: true, removeTop: true,
...@@ -218,7 +219,7 @@ class _MainPageState extends State<MainPage> { ...@@ -218,7 +219,7 @@ class _MainPageState extends State<MainPage> {
}, },
child: Card( child: Card(
color: thisQueue.isSelected color: thisQueue.isSelected
? Colors.blue ? Colors.lightGreen
: Colors.black38, : Colors.black38,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius:
...@@ -245,8 +246,8 @@ class _MainPageState extends State<MainPage> { ...@@ -245,8 +246,8 @@ class _MainPageState extends State<MainPage> {
setToReady(queueSelected); setToReady(queueSelected);
}, },
child: Container( child: Container(
width: 800, width: MediaQuery.of(context).size.width * 0.4,
height: 100, height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightBlue, color: Colors.lightBlue,
alignment: Alignment.center, alignment: Alignment.center,
child: InkWell( child: InkWell(
...@@ -266,9 +267,11 @@ class _MainPageState extends State<MainPage> { ...@@ -266,9 +267,11 @@ class _MainPageState extends State<MainPage> {
Flexible( Flexible(
flex: 1, flex: 1,
child: Container( child: Container(
width: MediaQuery.of(context).size.width * 0.2,
height: MediaQuery.of(context).size.height * 1,
color: Colors.blueGrey, color: Colors.blueGrey,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
// Container( // Container(
// width: 400, // width: 400,
...@@ -310,14 +313,14 @@ class _MainPageState extends State<MainPage> { ...@@ -310,14 +313,14 @@ class _MainPageState extends State<MainPage> {
); );
}, },
child: Container( child: Container(
width: 400, width: MediaQuery.of(context).size.width * 0.18,
height: 80, height: MediaQuery.of(context).size.height * 0.07,
margin: EdgeInsets.all(10), margin: EdgeInsets.all(10),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(20), Radius.circular(20),
), ),
color: Colors.amber, color: Colors.red,
), ),
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
...@@ -339,9 +342,9 @@ class _MainPageState extends State<MainPage> { ...@@ -339,9 +342,9 @@ class _MainPageState extends State<MainPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Container( Container(
width: 1000, width: MediaQuery.of(context).size.width * 0.4,
height: 100, height: MediaQuery.of(context).size.height * 0.1,
color: Colors.green, color: Colors.lightGreen,
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
"READY", "READY",
...@@ -350,8 +353,8 @@ class _MainPageState extends State<MainPage> { ...@@ -350,8 +353,8 @@ class _MainPageState extends State<MainPage> {
), ),
), ),
Container( Container(
width: 700, width: MediaQuery.of(context).size.width * 0.38,
height: 700, height: MediaQuery.of(context).size.height * 0.75,
child: MediaQuery.removePadding( child: MediaQuery.removePadding(
context: context, context: context,
removeTop: true, removeTop: true,
...@@ -504,8 +507,9 @@ class _MainPageState extends State<MainPage> { ...@@ -504,8 +507,9 @@ class _MainPageState extends State<MainPage> {
setToQueue(readySelected); setToQueue(readySelected);
}, },
child: Container( child: Container(
height: 100, width: MediaQuery.of(context).size.width * 0.2,
color: Colors.green, height: MediaQuery.of(context).size.height * 0.1,
color: Colors.lightGreen,
alignment: Alignment.center, alignment: Alignment.center,
child: InkWell( child: InkWell(
onTap: () => setToQueue(readySelected), onTap: () => setToQueue(readySelected),
...@@ -526,7 +530,8 @@ class _MainPageState extends State<MainPage> { ...@@ -526,7 +530,8 @@ class _MainPageState extends State<MainPage> {
setToPickUp(readySelected); setToPickUp(readySelected);
}, },
child: Container( child: Container(
height: 100, width: MediaQuery.of(context).size.width * 0.2,
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.black26, color: Colors.black26,
alignment: Alignment.center, alignment: Alignment.center,
child: InkWell( 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: ...@@ -156,6 +156,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" 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: matcher:
dependency: transitive dependency: transitive
description: description:
......
...@@ -37,6 +37,7 @@ dependencies: ...@@ -37,6 +37,7 @@ dependencies:
multi_select_flutter: ^4.0.0 multi_select_flutter: ^4.0.0
shared_preferences: ^2.0.13 shared_preferences: ^2.0.13
uuid: ^3.0.6 uuid: ^3.0.6
loading_animations: ^2.2.0
dev_dependencies: dev_dependencies:
...@@ -48,8 +49,8 @@ dev_dependencies: ...@@ -48,8 +49,8 @@ dev_dependencies:
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter. # The following section is specific to Flutter.
flutter: flutter:
# assets: assets:
# - assets/baseurl.json - assets/baseurl.json
# The following line ensures that the Material Icons font is # The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in # 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