Commit 51056ab5 authored by Arham Aulia Nugraha's avatar Arham Aulia Nugraha
parents 85d2ba63 d65976f2
...@@ -3,7 +3,7 @@ import 'dart:convert'; ...@@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:medapp_eksad/model/wa_model.dart'; import 'package:medapp_eksad/model/wa_model.dart';
Future<bool> savewa(nama, nohp) async { Future<bool> saveWa(nama, nohp) async {
final response = await http.post( final response = await http.post(
Uri.parse('http://10.3.4.231:8081/medapp/v1/api/whatapps/save'), Uri.parse('http://10.3.4.231:8081/medapp/v1/api/whatapps/save'),
body: jsonEncode({ body: jsonEncode({
...@@ -19,7 +19,7 @@ Future<bool> savewa(nama, nohp) async { ...@@ -19,7 +19,7 @@ Future<bool> savewa(nama, nohp) async {
return false; return false;
} }
} }
Future<List<dynamic>> showa() async { Future<List<dynamic>> getWA () async {
var response = await http var response = await http
.get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/whatapps/get')); .get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/whatapps/get'));
var resultJson = jsonDecode(response.body)['data']; var resultJson = jsonDecode(response.body)['data'];
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:medapp_eksad/api/wa_api.dart';
class Dashboard3 extends StatefulWidget { class Dashboard3 extends StatefulWidget {
...@@ -40,8 +41,11 @@ class _Dashboard3State extends State<Dashboard3> { ...@@ -40,8 +41,11 @@ class _Dashboard3State extends State<Dashboard3> {
ListWhatsapp=ListWhatsapp; ListWhatsapp=ListWhatsapp;
}); });
} }
final TextEditingController nameController = TextEditingController();
final TextEditingController phoneController = TextEditingController(); final TextEditingController waController = TextEditingController();
final formKey = GlobalKey<FormState>();
String nameWa = '';
String whatsapp = '';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -88,17 +92,47 @@ class _Dashboard3State extends State<Dashboard3> { ...@@ -88,17 +92,47 @@ class _Dashboard3State extends State<Dashboard3> {
), ),
), ),
Form( Form(
key: formKey,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Container(
height: 48,
width: 120,
child: TextFormField(
controller: nameController,
//initialValue: '+62',
decoration: const InputDecoration(
labelText: "Enter a name",
hintText: 'Ex: Jaenudin',
fillColor: Colors.white,
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide:
BorderSide(width: 1, color: Colors.blue),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide:
BorderSide(width: 1, color: Colors.blue),
),
),
onChanged: (value) => nameWa = value,
),
),
SizedBox(width: 15,),
Container( Container(
height: 48, height: 48,
width: 250, width: 250,
child: TextFormField( child: TextFormField(
controller: phoneController, controller: waController,
//initialValue: '+62',
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: "Enter a whatsapp number", labelText: "Enter a whatsapp number",
hintText: 'Ex: 62xxxxxxxxxxx',
fillColor: Colors.white, fillColor: Colors.white,
filled: true, filled: true,
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
...@@ -112,6 +146,7 @@ class _Dashboard3State extends State<Dashboard3> { ...@@ -112,6 +146,7 @@ class _Dashboard3State extends State<Dashboard3> {
BorderSide(width: 1, color: Colors.blue), BorderSide(width: 1, color: Colors.blue),
), ),
), ),
onChanged: (value) => whatsapp = value,
), ),
), ),
SizedBox(width: 15,), SizedBox(width: 15,),
...@@ -119,7 +154,33 @@ class _Dashboard3State extends State<Dashboard3> { ...@@ -119,7 +154,33 @@ class _Dashboard3State extends State<Dashboard3> {
height : 45, height : 45,
width : 175, width : 175,
child: ElevatedButton( child: ElevatedButton(
onPressed: (){}, onPressed: (){
if(whatsapp.trim().isEmpty){
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Number Can\'t Be Empty')),
);
}else {
nameController.clear();
waController.clear();
saveWa(nameWa, whatsapp).then(
(isSuccess) {
if (isSuccess) {
setState(() {});
Scaffold.of(this.context).showSnackBar(
const SnackBar(
content: Text("Input Data success")));
} else {
Scaffold.of(this.context).showSnackBar(
const SnackBar(
content: Text("Input Data failed!!!")));
}
},
);
}
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
primary: Colors.blueAccent[200], primary: Colors.blueAccent[200],
onSurface: Colors.white, onSurface: Colors.white,
......
...@@ -10,7 +10,7 @@ class WAChat extends StatelessWidget { ...@@ -10,7 +10,7 @@ class WAChat extends StatelessWidget {
required String message, required String message,
}) async { }) async {
String url() { String url() {
return "https://api.whatsapp.com/send?phone=+62$phone&text=${Uri.parse(message)}"; return "https://api.whatsapp.com/send?phone=$phone&text=${Uri.parse(message)}";
} }
if (await canLaunch(url())) { if (await canLaunch(url())) {
...@@ -26,25 +26,17 @@ class WAChat extends StatelessWidget { ...@@ -26,25 +26,17 @@ class WAChat extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FloatingActionButton( return FloatingActionButton(
onPressed: () {
launchWhatsApp(
//phone: 81807890777,
phone: 87701892981,
message:
'Hallo, saya tertarik dan saya ingin tahu lebih lanjut tentang program Medapp by EKSAD');
},
backgroundColor: Colors.green, backgroundColor: Colors.green,
child: GestureDetector( onPressed: (){
onTap: () {
springController.play( springController.play(
motion: Motion.reverse, motion: Motion.reverse,
animDuration: const Duration(milliseconds: 1000), animDuration: const Duration(milliseconds: 1000),
curve: Curves.easeInBack, curve: Curves.easeInBack,
delay: const Duration(milliseconds: 100)); delay: const Duration(milliseconds: 100));
launchWhatsApp( launchWhatsApp(
phone: 6281807890777, phone: 6287701892981,
message: message:
'Hallo, saya tertarik dengan produk EKSAD dan saya ingin tahu lebih lanjut tentang program Protalent'); 'Hallo, saya tertarik dan saya ingin tahu lebih lanjut tentang program Medapp dari EKSAD');
}, },
child: Spring.rotate( child: Spring.rotate(
endAngle: 360 * 10, endAngle: 360 * 10,
...@@ -52,9 +44,9 @@ class WAChat extends StatelessWidget { ...@@ -52,9 +44,9 @@ class WAChat extends StatelessWidget {
springController: springController, springController: springController,
alignment: Alignment.center, alignment: Alignment.center,
animStatus: (AnimStatus status) {}, animStatus: (AnimStatus status) {},
child: const Icon(Icons.whatsapp, size: 30), child: const Icon(Icons.whatsapp, size: 40,color: Colors.white,),
),
), ),
); );
} }
} }
//phone: 81807890777,
\ No newline at end of file
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