I managed sending email via gmail Api, but could you help me how to send attachment?

var encodedSubject = base64Url.encode(utf8.encode(subject));
subject = '=?utf-8?B?$encodedSubject?=';
var content =
        '''Content-Type: text/html; charset=utf-8\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nto: ${recipients[0]}\nsender: $userId\nsubject: $subject\n\n$body''';
    var encodedJson =
        json.encode({'raw': base64Url.encode(utf8.encode(content))});

String url = 'https://www.googleapis.com/gmail/v1/users/' +
        userId +

final http.Response response =
        await http.post(url, headers: header, body: encodedJson);

Solution 1: Raserhin

I would strongly encourage you to take a look at the API documentation and more specifically at the part of Creating messages with attachments:

Creating a message with an attachment is like creating any other message, but the process of uploading the file as a multi-part MIME message depends on the programming language.

Also there is a whole section just describing the necessary request (without libraries) to upload attachments, there are multiple ways you can do this depending on your file or expected output.

Also it may be useful to take a look at the mime repository for mime multipart handling in dart.