grades_native_fibonacci 0.0.1 copy "grades_native_fibonacci: ^0.0.1" to clipboard
grades_native_fibonacci: ^0.0.1 copied to clipboard

Test FFI plugin project that uses native code for computation.

example/lib/main.dart

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

import 'package:grades_native_fibonacci/grades_native_fibonacci.dart' as grades_native_fibonacci;

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

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

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

class _MyAppState extends State<MyApp> {
  late int fibResult;
  late Future<int> fibAsyncResult;

  @override
  void initState() {
    super.initState();
    fibResult = grades_native_fibonacci.fib(4);
    fibAsyncResult = grades_native_fibonacci.fibAsync(5);
  }

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 25);
    const spacerSmall = SizedBox(height: 10);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              children: [
                const Text(
                  'This calls a native function through FFI that is shipped as source in the package. '
                  'The native code is built as part of the Flutter Runner build.',
                  style: textStyle,
                  textAlign: TextAlign.center,
                ),
                spacerSmall,
                Text(
                  'fib(4) = $fibResult',
                  style: textStyle,
                  textAlign: TextAlign.center,
                ),
                spacerSmall,
                FutureBuilder<int>(
                  future: fibAsyncResult,
                  builder: (BuildContext context, AsyncSnapshot<int> value) {
                    final displayValue = (value.hasData) ? value.data : 'loading';
                    return Text(
                      'await fibAsync(5) = $displayValue',
                      style: textStyle,
                      textAlign: TextAlign.center,
                    );
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

Test FFI plugin project that uses native code for computation.

Repository (GitHub)

Documentation

API reference

License

BSL-1.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on grades_native_fibonacci