durt2 0.3.4
durt2: ^0.3.4 copied to clipboard
Dart library for interacting with Duniter v2s blockchains. Provides wallet management, transaction signing, Squid GraphQL requests, and more
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:durt2/durt2.dart';
import 'screens/connection_screen.dart';
import 'screens/wallet_screen.dart';
import 'screens/balance_screen.dart';
import 'screens/payment_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Durt2 with gtest network by default using singleton pattern
try {
// Create Durt instance and initialize it (this sets Durt._instance)
final durt = Durt();
await durt.init(network: Networks.gtest, keyPairType: KeyPairType.ed25519);
// Connect to the network - now we can use either durt or Durt.i
await durt.connect();
} catch (e) {
print('Failed to initialize Durt2: $e');
print('App will start - use Connection screen to retry initialization');
}
runApp(const DurtExampleApp());
}
class DurtExampleApp extends StatelessWidget {
const DurtExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Durt2 Example',
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true),
home: const MainScreen(),
);
}
}
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
int _selectedIndex = 0;
final List<Widget> _screens = [const ConnectionScreen(), const WalletScreen(), const BalanceScreen(), const PaymentScreen()];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _screens[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectedIndex,
onTap: _onItemTapped,
items: const [
BottomNavigationBarItem(icon: Icon(Icons.wifi), label: 'Connection'),
BottomNavigationBarItem(icon: Icon(Icons.account_balance_wallet), label: 'Wallets'),
BottomNavigationBarItem(icon: Icon(Icons.account_balance), label: 'Balance'),
BottomNavigationBarItem(icon: Icon(Icons.send), label: 'Payment'),
],
),
);
}
}