Local image (picture taken) into base64 string

Database & APIs

Hi all,

I need to transform an image into a base64 string.

I imagine the flow like this:

Take a picture -> convert to base64 -> insert it on a SQLite database

What have you tried so far?

Tried a custom function, but it doesnยดt save.

import 'dart:convert';
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/sqlite/sqlite_manager.dart';

String imgtobase64(List<String> canhoto) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  // convert image to base64
  Uint8List bytes = Uint8List.fromList(canhoto.codeUnits);
  String base64Image = base64Encode(bytes);
  return base64Image;

  /// MODIFY CODE ONLY ABOVE THIS LINE
}
Did you check FlutterFlow's Documentation for this topic?
Yes
2
5 replies