nissy-fmc

A Rubik's cube FMC assistant
git clone https://git.tronto.net/nissy-fmc
Download | Log | Files | Refs | README | LICENSE

main.dart (3163B)


      1 import 'dart:typed_data';
      2 import 'dart:async';
      3 import 'package:flutter/material.dart';
      4 import 'package:flutter/services.dart' show rootBundle;
      5 
      6 import 'package:nissy_flutter_ffi/nissy_flutter_ffi.dart' as nissy_flutter_ffi;
      7 
      8 void main() {
      9   runApp(const MyApp());
     10 }
     11 
     12 class MyApp extends StatefulWidget {
     13   const MyApp({super.key});
     14 
     15   @override
     16   State<MyApp> createState() => _MyAppState();
     17 }
     18 
     19 class _MyAppState extends State<MyApp> {
     20   @override
     21 
     22   void initState() {
     23     super.initState();
     24   }
     25 
     26   @override
     27   Widget build(BuildContext context) {
     28     const textStyle = TextStyle(fontSize: 25);
     29     const spacerSmall = SizedBox(height: 10);
     30     return MaterialApp(
     31       home: Scaffold(
     32         appBar: AppBar(
     33           title: const Text('Nissy ffi test run'),
     34         ),
     35         body: SingleChildScrollView(
     36           child: Container(
     37             padding: const EdgeInsets.all(10),
     38             child: NissyFutureBuilder(),
     39 	  ),
     40         ),
     41       ),
     42     );
     43   }
     44 }
     45 
     46 class NissyFutureBuilder extends StatefulWidget {
     47   const NissyFutureBuilder({super.key});
     48 
     49   @override
     50   State<NissyFutureBuilder> createState() => NissyFutureBuilderState();
     51 }
     52 
     53 
     54 // Copied from https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
     55 class NissyFutureBuilderState extends State<NissyFutureBuilder> {
     56   final Future<String> _calculation = Future<String>.delayed(
     57     const Duration(seconds: 2),
     58     () => 'Data Loaded',
     59   );
     60 
     61   @override
     62   Widget build(BuildContext context) {
     63     return DefaultTextStyle(
     64       style: Theme.of(context).textTheme.displayMedium!,
     65       textAlign: TextAlign.center,
     66       child: FutureBuilder<String>(
     67         future: _calculation, // a previously-obtained Future<String> or null
     68         builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
     69           List<Widget> children;
     70           if (snapshot.hasData) {
     71             children = <Widget>[
     72               const Icon(
     73                 Icons.check_circle_outline,
     74                 color: Colors.green,
     75                 size: 60,
     76               ),
     77               Padding(
     78                 padding: const EdgeInsets.only(top: 16),
     79                 child: Text('Result: ${snapshot.data}'),
     80               ),
     81             ];
     82           } else if (snapshot.hasError) {
     83             children = <Widget>[
     84               const Icon(
     85                 Icons.error_outline,
     86                 color: Colors.red,
     87                 size: 60,
     88               ),
     89               Padding(
     90                 padding: const EdgeInsets.only(top: 16),
     91                 child: Text('Error: ${snapshot.error}'),
     92               ),
     93             ];
     94           } else {
     95             children = const <Widget>[
     96               SizedBox(
     97                 width: 60,
     98                 height: 60,
     99                 child: CircularProgressIndicator(),
    100               ),
    101               Padding(
    102                 padding: EdgeInsets.only(top: 16),
    103                 child: Text('Awaiting result...'),
    104               ),
    105             ];
    106           }
    107           return Center(
    108             child: Column(
    109               mainAxisAlignment: MainAxisAlignment.center,
    110               children: children,
    111             ),
    112           );
    113         },
    114       ),
    115     );
    116   }
    117 }