flutter_malvo_connect 0.1.0 copy "flutter_malvo_connect: ^0.1.0" to clipboard
flutter_malvo_connect: ^0.1.0 copied to clipboard

Malvo Connect SDK for Flutter — a drop-in WebView widget that lets your users link their bank accounts (Open Finance Brasil) through the hosted Malvo Connect widget.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_malvo_connect/flutter_malvo_connect.dart';

void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Malvo Connect Example',
      theme: ThemeData(colorSchemeSeed: const Color(0xFF1339D4)),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final _tokenCtrl = TextEditingController();

  // Use http://10.0.2.2:5173 on the Android emulator to reach a local
  // frontend, or your malvo-web origin in production.
  final _baseUrlCtrl = TextEditingController(text: 'https://malvo.io');

  final List<String> _log = [];

  void _append(String line) {
    setState(() => _log.insert(0, line));
    debugPrint(line);
  }

  Future<void> _open() async {
    final token = _tokenCtrl.text.trim();
    if (token.isEmpty) return;
    await Navigator.of(context).push(
      MaterialPageRoute<void>(
        builder: (_) => ConnectPage(
          connectToken: token,
          baseUrl: _baseUrlCtrl.text.trim(),
          onSuccess: (data) => _append('SUCCESS: item ${data['item']?['id']}'),
          onError: (error) =>
              _append('ERROR: ${error['code']} — ${error['message']}'),
          onClose: () => _append('CLOSE'),
          onEvent: (event) => _append('EVENT: ${event['type']}'),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _tokenCtrl.dispose();
    _baseUrlCtrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Malvo Connect')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            TextField(
              controller: _baseUrlCtrl,
              decoration: const InputDecoration(labelText: 'Base URL'),
            ),
            const SizedBox(height: 12),
            TextField(
              controller: _tokenCtrl,
              minLines: 1,
              maxLines: 3,
              decoration: const InputDecoration(
                labelText: 'Connect Token',
                hintText: 'cole o accessToken do /connect_token',
              ),
            ),
            const SizedBox(height: 12),
            FilledButton(onPressed: _open, child: const Text('Abrir widget')),
            const SizedBox(height: 16),
            const Text('Eventos:'),
            const SizedBox(height: 8),
            Expanded(
              child: ListView.builder(
                itemCount: _log.length,
                itemBuilder: (_, i) => Text(_log[i]),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class ConnectPage extends StatelessWidget {
  const ConnectPage({
    super.key,
    required this.connectToken,
    required this.baseUrl,
    this.onSuccess,
    this.onError,
    this.onClose,
    this.onEvent,
  });

  final String connectToken;
  final String baseUrl;
  final void Function(dynamic data)? onSuccess;
  final void Function(dynamic error)? onError;
  final VoidCallback? onClose;
  final void Function(dynamic payload)? onEvent;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: MalvoConnect(
          connectToken: connectToken,
          baseUrl: baseUrl,
          includeSandbox: true,
          onSuccess: (data) {
            onSuccess?.call(data);
            Navigator.of(context).maybePop();
          },
          onError: onError,
          onClose: () {
            onClose?.call();
            Navigator.of(context).maybePop();
          },
          onEvent: onEvent,
        ),
      ),
    );
  }
}
0
likes
150
points
75
downloads

Documentation

API reference

Publisher

verified publishermalvo.io

Weekly Downloads

Malvo Connect SDK for Flutter — a drop-in WebView widget that lets your users link their bank accounts (Open Finance Brasil) through the hosted Malvo Connect widget.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

app_links, flutter, url_launcher, webview_flutter

More

Packages that depend on flutter_malvo_connect