encryptions 0.0.2 copy "encryptions: ^0.0.2" to clipboard
encryptions: ^0.0.2 copied to clipboard

outdated

A plugin for using native Argon2/AES in Android and IOS

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Future<List<Report>> reports;

  @override
  void initState() {
    super.initState();
    reports = test();
  }

  static const headerStyle =
      TextStyle(fontSize: 16, fontWeight: FontWeight.bold);
  static const successStyle = TextStyle(fontSize: 16, color: Colors.green);
  static const errorStyle = TextStyle(fontSize: 16, color: Colors.red);
  static const padding = EdgeInsets.all(5.0);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Padding(
          padding: const EdgeInsets.only(top: 20.0, left: 5, right: 5),
          child: _renderReport(),
        ),
      ),
    );
  }

  Widget _renderTable(List<TableRow> rows) {
    return SingleChildScrollView(
      child: Table(
        border: new TableBorder.all(width: 1.0, color: Colors.grey),
        children: <TableRow>[
          TableRow(children: <Widget>[
            TableCell(
              child: Padding(
                padding: padding,
                child: Text('Test', style: headerStyle),
              ),
            ),
            TableCell(
              child: Padding(
                padding: padding,
                child: Text('Result', style: headerStyle),
              ),
            ),
          ]),
          ...rows
        ],
      ),
    );
  }

  TableRow _createRow(Report report) {
    return TableRow(key: ObjectKey(report.name), children: <Widget>[
      TableCell(
        child: Padding(
          padding: padding,
          child: Text(report.name),
        ),
      ),
      TableCell(
        child: Padding(
          padding: padding,
          child: Text(
            "${report.success}",
            style: report.success ? successStyle : errorStyle,
          ),
        ),
      ),
    ]);
  }

  Widget _renderReport() {
    return FutureBuilder<List<Report>>(
      future: reports,
      builder: (_, snapshot) {
        switch (snapshot.connectionState) {
          case ConnectionState.done:
            if (snapshot.hasError) {
              print('got error! ${snapshot.error}');
              return Text("Error:${snapshot.error}");
            }
            print("Done! ${snapshot.data}");
            return _renderTable(
                snapshot.data.map((report) => _createRow(report)).toList());
          default:
            return Center(
              child: Text("Testing..."),
            );
        }
      },
    );
  }

  Future<List<Report>> test() async {
    List<Report> reports = [];
    for (int i = 0; i < tests.length; i++) {
      PlatformTest t = tests[i];
      bool success;
      try {
        success = await t.executor();
      } catch (err, stack) {
        print(err);
        print(stack);
        success = false;
      }
      reports.add(Report(t.name, success));
    }
    return reports;
  }
}
13
likes
0
pub points
86%
popularity

Publisher

unverified uploader

A plugin for using native Argon2/AES in Android and IOS

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

convert, flutter

More

Packages that depend on encryptions