Quickstarters
Feature Overview
How to Build a Backend for Flutter?
40 min
introduction in this tutorial, you’ll learn how to build a backend for flutter using back4app, an open source and reliable backend as a service (baas) we’ll walk through integrating essential back4app features—such as database management, cloud functions, restful apis, graphql apis, and user authentication—into your flutter project you’ll also discover how to handle real time updates using live queries by using back4app’s powerful backend servers, you can skip much of the manual configuration and focus on creating a dynamic flutter app this guide will show flutter developers how to set up a secure, scalable, and robust backend structure that effortlessly communicates with your client side we’ll also highlight the advantages of letting back4app handle heavy lifting—like hosting, user authentication, and server logic—so you can benefit from features like automatic scaling, advanced security, and simplified maintenance if you have a flutter project and want to save countless hours of backend setup, this is the right place to start by the end of this tutorial, you’ll understand the type of backend you can create with back4app and be ready to extend your backend services for a production ready application or integrate more complex functionalities, such as external apis and advanced user authentication let’s get started! prerequisites to complete this tutorial, you will need a back4app account and a new back4app project getting started with back4app https //www back4app com/docs/get started/new parse app if you do not have an account, you can create one for free follow the guide above to get your project ready basic flutter development environment ensure you have the flutter sdk https //docs flutter dev/get started/install installed and set up also, confirm you have an ide (like android studio or vs code) configured for flutter dart (programming language) environment usually this is installed along with flutter make sure you can import dart packages without error familiarity with flutter fundamentals flutter official documentation https //docs flutter dev if you’re new to flutter, review the official docs or a beginner’s tutorial before starting make sure you have all of these prerequisites in place having your back4app project set up and your local flutter environment configured will help you follow along more easily step 1 – creating a new project on back4app and connecting create a new project the first step in building your flutter backend on back4app is to create a new project if you have not already created one, follow these steps log in to your back4app account click the “new app” button in your back4app dashboard give your app a name (e g , “flutter backend tutorial”) once the project is created, you will see it listed in your back4app dashboard this project will be the foundation for all the backend configurations we will discuss install and initialize the parse sdk in your flutter app back4app relies on the parse platform to manage your data, real time updates, user authentication, and more to connect your flutter project to back4app, follow these steps add the parse flutter sdk to your app dependencies parse server sdk flutter ^4 0 0 import the parse package in your main dart (or wherever you initialize your app) import 'package\ parse server sdk flutter/parse server sdk flutter dart'; import 'package\ flutter/material dart'; void main() async { widgetsflutterbinding ensureinitialized(); const keyapplicationid = 'your application id'; const keyparseserverurl = 'https //parseapi back4app com'; const keyclientkey = 'your client key'; // initialize parse with debug set to true await parse() initialize( keyapplicationid, keyparseserverurl, clientkey keyclientkey, autosendsessionid true, debug true, ); runapp(const myapp()); } class myapp extends statelesswidget { const myapp({key? key}) super(key key); @override widget build(buildcontext context) { return materialapp( title 'flutter + back4app example', theme themedata(primaryswatch colors blue), home const scaffold( body center( child text('hello from flutter + back4app!'), ), ), ); } } in your back4app dashboard, go to your app’s security & keys section to find your application id , client key , and parse server url replace the placeholders above with your own credentials with this initialization, every request from your flutter app is securely routed to your back4app instance remember that the master key should never be used on the client side of your flutter app if you need the master key, keep it on the server or in a secure environment step 2 – setting up the database creating a data model once your flutter app is connected to back4app, you can start designing your database schema you can do this manually from the back4app dashboard navigate to the “database” section in your dashboard create a new class (e g , “todo”), and add relevant columns (e g , title, iscompleted) back4app also provides an ai agent to help with automatic schema creation open the ai agent from your app dashboard or the menu describe your data model in simple language (e g , “create a new todo app with a complete class schema ”) let the ai agent create the schema for you this streamlines data architecture setup if you want fields to be created automatically, you can simply start saving objects from your app—parse supports schema creation on the fly creating a data model using the ai agent if you choose to use the back4app ai agent, just provide a short description, and it will build or suggest a schema for you this is an excellent way to speed up the initial data modeling phase of your flutter project reading and writing data using flutter parse sdk below is a simple example demonstrating how to create and retrieve objects using the parse flutter sdk import 'package\ parse server sdk flutter/parse server sdk flutter dart'; future\<void> createtodoitem(string title, bool iscompleted) async { final todo = parseobject('todo') set('title', title) set('iscompleted', iscompleted); final response = await todo save(); if (response success && response result != null) { print('todo saved successfully ${response result}'); } else { print('error saving todo ${response error? message}'); } } future\<list\<parseobject>?> fetchtodos() async { final querybuilder\<parseobject> querytodo = querybuilder\<parseobject>(parseobject('todo')); final response = await querytodo query(); if (response success && response results != null) { print('fetched todo items ${response results}'); return response results as list\<parseobject>; } else { print('error fetching todos ${response error? message}'); return null; } } with this, you can directly interact with your back4app database from your flutter app simply call createtodoitem('feed the cat', false) or fetchtodos() to write and read data reading and writing data using rest api if you need to integrate with other services or prefer a more traditional approach, you can still use the back4app rest api curl x post \\ h "x parse application id your application id" \\ h "x parse rest api key your rest api key" \\ h "content type application/json" \\ d '{"title" "buy groceries", "iscompleted" false}' \\ https //parseapi back4app com/classes/todo reading and writing data using graphql api back4app also offers a graphql endpoint mutation { createtodo(input { fields { title "clean the house" iscompleted false } }) { todo { objectid title iscompleted } } } this gives you flexibility to build whatever approach works best for your flutter app working with live queries back4app provides live queries so you can receive real time updates to your data enable live queries in the back4app dashboard (server settings) and then use the parse livequery flutter client import 'package\ parse server sdk flutter/parse server sdk flutter dart'; import 'package\ parse server sdk flutter/live query dart'; future\<void> subscribetotodos() async { final livequery = livequery(); final query = querybuilder\<parseobject>(parseobject('todo')); subscription subscription = await livequery client subscribe(query); subscription on(livequeryevent create, (value) { print('new todo created $value'); }); subscription on(livequeryevent update, (value) { print('todo updated $value'); }); subscription on(livequeryevent delete, (value) { print('todo deleted $value'); }); } with this subscription, you can listen for data changes as they happen this is fantastic for building collaborative apps where multiple users see live data updates once hot reload is triggered, your subscription will remain unless the app restarts step 3 – applying security with acls and clps what are acls and clps? back4app uses acls (access control lists) and clps (class level permissions) to restrict who can read or write data on both object and class levels this layer ensures your data is protected from unauthorized access setting up class level permissions in your back4app dashboard, go to database and select a class (e g , “todo”) navigate to class level permissions set defaults (e g , only authenticated users can create new objects) configuring acls in code you can also apply acls at the object level from the flutter code import 'package\ parse server sdk flutter/parse server sdk flutter dart'; future\<void> createprivatetodo(parseuser owneruser, string title) async { final todo = parseobject('todo') set('title', title); final acl = parseacl(owner owneruser); acl setpublicreadaccess(allowed false); acl setpublicwriteaccess(allowed false); todo setacl(acl); final response = await todo save(); if (response success) { print('private todo saved '); } else { print('error ${response error? message}'); } } by combining clps and acls, you can ensure that only the right people or roles can access or modify specific data step 4 – writing cloud code functions why cloud code? cloud code allows you to run server side logic without manually setting up any backend servers this is perfect for validating data, integrating with external services, or enforcing certain rules in your backend as a service (baas) example function here is an example cloud function that calculates the length of a text // main js in your cloud code parse cloud define('calculatetextlength', async (request) => { const { text } = request params; if (!text) { throw new error('no text provided'); } return { length text length }; }); you can deploy this code via the back4app cli or in your app’s dashboard under cloud code deployment using back4app cli b4a configure accountkey b4a deploy using the dashboard in your app’s dashboard, go to cloud code > functions paste the javascript code click deploy calling cloud code from flutter import 'package\ parse server sdk flutter/parse server sdk flutter dart'; future\<void> gettextlength(string text) async { final function = parsecloudfunction('calculatetextlength'); final params = \<string, dynamic>{'text' text}; final parseresponse result = await function execute(parameters params); if (result success && result result != null) { print('text length ${result result\['length']}'); } else { print('error calling cloud code ${result error? message}'); } } this secure approach ensures sensitive logic remains on the server, while your flutter app simply makes requests step 5 – configuring authentication enable user authentication back4app uses the parse user class to handle user sign up and login by default, parse takes care of password hashing, session tokens, and secure storage import 'package\ parse server sdk flutter/parse server sdk flutter dart'; future\<void> signupuser(string username, string password, string email) async { final user = parseuser(username, password, email); final response = await user signup(); if (response success) { print('user signed up successfully!'); } else { print('sign up error ${response error? message}'); } } future\<void> loginuser(string username, string password) async { final user = parseuser(username, password, null); final response = await user login(); if (response success) { print('user logged in ${response result}'); } else { print('login error ${response error? message}'); } } social login back4app supports integrations with google, apple, facebook, and more each provider has a specific approach and may require additional libraries (e g , for facebook or google sign in) you can then call await parseuser loginwith('facebook', \<string, dynamic>{ 'id' 'user facebook id', 'access token' 'facebook access token', 'expiration date' 'date' }); adjust the parameters according to the provider’s documentation step 6 – handling file storage setting up file storage you can store images, documents, or other media files using parsefile back4app secures these files and provides a url for retrieval import 'dart\ io'; import 'package\ parse server sdk flutter/parse server sdk flutter dart'; import 'package\ image picker/image picker dart'; future\<void> uploadimage() async { final picker = imagepicker(); final xfile? pickedfile = await picker pickimage(source imagesource gallery); if (pickedfile == null) { print('no file selected '); return; } final parsefile = parsefile(file(pickedfile path)); final response = await parsefile save(); if (response success) { print('file saved ${parsefile url}'); } else { print('error uploading file ${response error? message}'); } } security considerations you can define who has access to files (public, authenticated users, or restricted) by combining file level security with acls this ensures your file data remains safe step 7 – email verification and password reset why they matter email verification confirms that a user owns the email address provided, while password reset flows enhance user experience and security dashboard configuration go to your app’s email settings in the back4app dashboard enable email verification and password reset configure email templates or your custom domain if needed these settings let your flutter app automatically handle user ownership checks and password recovery implementation in flutter final user = parseuser('testuser', 'password123', 'test\@example com'); final signupresponse = await user signup(); if (signupresponse success) { // the user will receive a verification email } // for password reset final resetresponse = await parseuser requestpasswordreset('test\@example com'); if (resetresponse success) { print('reset email sent successfully!'); } step 8 – scheduling tasks with cloud jobs cloud jobs you might want to schedule recurring tasks (like cleaning old data or sending periodic emails) cloud jobs let you do just that // main js parse cloud job('cleanupoldtodos', async (request) => { const todo = parse object extend('todo'); const query = new parse query(todo); const now = new date(); const thirty days = 30 24 60 60 1000; const cutoff = new date(now thirty days); query lessthan('createdat', cutoff); const oldtodos = await query find({ usemasterkey true }); await parse object destroyall(oldtodos, { usemasterkey true }); return `deleted ${oldtodos length} old todos `; }); deploy this code, then go to app settings > server settings > background jobs in your back4app dashboard to schedule it step 9 – integrating webhooks what are webhooks? webhooks let your back4app app send http requests to an external service when certain events occur (like saving a new object) this is ideal for integrating with third party tools go to more > webhooks in your back4app dashboard and add webhook set your endpoint and triggers (e g , “new record in todo”) you can also manually configure webhooks in cloud code by making http requests in beforesave or aftersave triggers step 10 – exploring the back4app admin panel where to find it the back4app admin app is a user friendly interface that allows non technical team members to manage data (crud operations, data tasks, etc ) without needing to open the parse dashboard go to app dashboard > more > admin app click enable admin app you’ll create an admin user, choose a subdomain, and log in with the newly created credentials the admin app helps with quick data reviews and modifications conclusion in this tutorial, you learned how to build a backend for flutter using back4app and the parse flutter sdk you created classes, stored data, configured real time queries, applied security with acls and clps, wrote cloud functions, scheduled tasks, integrated webhooks, and explored the back4app admin panel this approach accelerates development by letting you focus on your flutter client side rather than complex server configuration the final string you have now is a functioning and secure backend that leverages restful apis, user authentication, and easy data manipulation you can integrate more advanced features any time—like additional cloud functions, external api calls, or custom roles next steps go production ready implement advanced caching, analytics, or role based access controls extend your app integrate third party services or build more cloud functions for specialized business logic consult the back4app documentation explore advanced security, performance tuning, logs analysis, and more learn more check out tutorials for live chat apps, location based services, or more complex data structures combine them with your flutter project for real world use cases by continuing to refine this setup, you’ll transform your flutter app into a powerful, scalable solution built on top of a robust backend service happy coding!