📄 Download Firebase DataBase in CSV file📄

Download your Firebase database to a CSV to keep all kinds of controls.

Step #1:

Create a new Project and add a bottom

Step #2:

Create a Custom Action.

or copy this code.

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

//imports agregados
import 'dart:convert' show utf8;
import 'package:download/download.dart';

Future descargarCSV(List<PaisRecord>? documento) async {
  documento = documento ?? [];

  // Add your function code here!
  String companyName = "Akteknologies";
  String companyAddress = "Alajuela, Costa Rica.";
  String header = "$companyName,$companyAddress\n\n";

  String fileContent = header + "nombre, continente, habitantes";

  documento.asMap().forEach((index, record) => fileContent = fileContent +
      "\n" +
      record.nombre.toString() +
      "," +
      record.continente.toString() +
      "," +
      record.habitantes.toString());

  final fileName = "Paises" + DateTime.now().toString() + ".csv";

  // Encode the string as a List<int> of UTF-8 bytes
  var bytes = utf8.encode(fileContent);

  final stream = Stream.fromIterable(bytes);
  return download(stream, fileName);
}

Step #3:

Create a DB in Firebase

Step #4:

Download CSV file

9
8 replies