I'm working on a flutter mobile app and I'm wondering about the cleanest way to send data to a springboot server.
CodePudding user response:
I don't know whether it will be the cleanest way or not but you can use REST APIs to get/send data from/to Springboot Server.
For more information: https://medium.com/nerd-for-tech/flutter-series-connecting-ui-to-spring-boot-backend-f9874dc3dcd5
For your Flutter Project structure, you can use BLoC or any other state management.
CodePudding user response:
You can use spring as RestAPI which has logic something like http method(get, post, put, delete..). (RestfulAPI is used many reason, one of reason is for various client.(mobile, web, pad,..))
You can send data from client to server on query string in uri, header or body.
CodePudding user response:
**you can use dio packge for any kind of apis its easy and best and you do not need any kind maping it will be by dio package own its own **
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:dio/dio.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:rent_house/screens/Navigation/navBar.dart';
Future<String> signupApis({
name,
email,
conatact,
address,
password,
type,
context,
}) async {
// isloading:true;
var apiURL = 'https://denga.r3therapeutic.com/public/api/register';
var formData = FormData.fromMap({
'name': name,
'email': email,
'contact': conatact,
'address': address,
'password': password,
'type': type,
});
//final prefs = await SharedPreferences.getInstance();
Dio dio = Dio();
Response responce;
try {
responce = await dio.post(
apiURL,
data: formData,
);
// print("response datra " responce.toString());
SharedPreferences pref = await SharedPreferences.getInstance();
var res1 = responce.data['user'];
var token = res1['token'];
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Navbar()),
);
Fluttertoast.showToast(
msg: "Login Successfull", backgroundColor: Colors.cyan);
return '';
} catch (e) {
Fluttertoast.showToast(
msg: "User Already exists", backgroundColor: Colors.cyan);
return 'some thing wrong';
}
}