agent_dart 1.0.0-dev.6 copy "agent_dart: ^1.0.0-dev.6" to clipboard
agent_dart: ^1.0.0-dev.6 copied to clipboard

An agent library built for Internet Computer, a plugin package for dart and flutter apps. Developers can build ones to interact with Dfinity's blockchain directly.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'counter.dart';
import 'init.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _count = 0;
  bool _loading = false;

  Counter? _counter;
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
    loading(true);
    readCount();
  }

  Future<void> initCounter() async {
    _counter = (await AgentFactory.create(
      canisterId: 'sbzkb-zqaaa-aaaaa-aaaiq-cai',
      url: 'https://03af-58-62-205-141.ngrok.io',
      // For Android emulator, please use 10.0.2.2 as endpoint
      idl: idl,
    ))
        .hook(Counter());
  }

  void loading(bool state) {
    setState(() {
      _loading = state;
    });
  }

  Future<void> readCount() async {
    if (_counter == null) {
      await initCounter();
    }
    final int c = await _counter!.count();
    loading(false);
    setState(() {
      _count = c;
    });
  }

  void increase() async {
    loading(true);
    await _counter!.add();
    readCount();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: const Text('Dfinity flutter Dapp'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(_loading ? 'loading contract count' : '$_count'),
              Container(
                height: 30,
              ),
              Container(
                height: 30,
              ),
              const Text('Please Login 👆'),
              Container(height: 30),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.add),
          onPressed: () async {
            increase();
          },
        ),
      ),
    );
  }
}
21
likes
0
pub points
64%
popularity

Publisher

verified publisherastrox.io

An agent library built for Internet Computer, a plugin package for dart and flutter apps. Developers can build ones to interact with Dfinity's blockchain directly.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

archive, args, basic_utils, bip32, bip39, cbor, collection, convert, crypto, ffi, fixnum, flutter, flutter_rust_bridge, http, js, meta, path, pinenacl, pointycastle, protobuf, recase, tuple, typed_data, uuid, validators

More

Packages that depend on agent_dart