Commit 34fbd5f8 authored by Budi Prasetyo's avatar Budi Prasetyo

post WA api

parent b72846d6
...@@ -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,14 +146,41 @@ class _Dashboard3State extends State<Dashboard3> { ...@@ -112,14 +146,41 @@ 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,),
Container( Container(
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())) {
...@@ -21,40 +21,32 @@ class WAChat extends StatelessWidget { ...@@ -21,40 +21,32 @@ class WAChat extends StatelessWidget {
} }
final SpringController springController = final SpringController springController =
SpringController(initialAnim: Motion.play); SpringController(initialAnim: Motion.play);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FloatingActionButton( return FloatingActionButton(
onPressed: () { backgroundColor: Colors.green,
onPressed: (){
springController.play(
motion: Motion.reverse,
animDuration: const Duration(milliseconds: 1000),
curve: Curves.easeInBack,
delay: const Duration(milliseconds: 100));
launchWhatsApp( launchWhatsApp(
//phone: 81807890777, phone: 6287701892981,
phone: 87701892981,
message: message:
'Hallo, saya tertarik dan saya ingin tahu lebih lanjut tentang program Medapp by EKSAD'); 'Hallo, saya tertarik dan saya ingin tahu lebih lanjut tentang program Medapp dari EKSAD');
}, },
backgroundColor: Colors.green, child: Spring.rotate(
child: GestureDetector( endAngle: 360 * 10,
onTap: () { animDuration: const Duration(seconds: 3 * 10),
springController.play( springController: springController,
motion: Motion.reverse, alignment: Alignment.center,
animDuration: const Duration(milliseconds: 1000), animStatus: (AnimStatus status) {},
curve: Curves.easeInBack, child: const Icon(Icons.whatsapp, size: 40,color: Colors.white,),
delay: const Duration(milliseconds: 100));
launchWhatsApp(
phone: 6281807890777,
message:
'Hallo, saya tertarik dengan produk EKSAD dan saya ingin tahu lebih lanjut tentang program Protalent');
},
child: Spring.rotate(
endAngle: 360 * 10,
animDuration: const Duration(seconds: 3 * 10),
springController: springController,
alignment: Alignment.center,
animStatus: (AnimStatus status) {},
child: const Icon(Icons.whatsapp, size: 30),
),
), ),
); );
} }
} }
//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