Skip to content

Instantly share code, notes, and snippets.

@Wizpna
Last active April 26, 2021 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wizpna/2228506a39a24a9e7cb9ac54d740a3a4 to your computer and use it in GitHub Desktop.
Save Wizpna/2228506a39a24a9e7cb9ac54d740a3a4 to your computer and use it in GitHub Desktop.
A simple project to demonstrate how to store data to Firebase without adding google-services.json file
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Services {
static showLoadingDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => new Dialog(
backgroundColor: Colors.transparent,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10.0),
color: Color(0xFFECF0F5),
),
height: 100,
width: 20,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CupertinoActivityIndicator(
radius: 15,
),
SizedBox(
height: 10,
),
Text(
"Please wait",
textAlign: TextAlign.center,
)
],
),
),
),
);
}
static Future save_record(BuildContext context, name, email, country) async {
showLoadingDialog(context);
//this endpoint below is for test, add your owm pipedream endpoint here
String url = Uri.encodeFull(
"https://a4b2180d68709437f526216fa9962bb.m.pipedream.net");
var body = json.encode({'name': name, 'email': email, 'country': country});
Map<String, String> headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
var response =
await http.Client().post(Uri.parse(url), headers: headers, body: body);
Map<String, dynamic> result = json.decode(response.body);
if(result['success'] == true){
Navigator.pop(context);
return result['success'];
}else{
Navigator.pop(context);
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment