flutter_call_outcome 0.0.3 icon indicating copy to clipboard operation
flutter_call_outcome: ^0.0.3 copied to clipboard

A dart package to simplify return data and exception from a function call

function_call_outcome #

Pub.dev Badge GitHub Build Badge MIT License Badge Flutter Platform Badge

This is a dart package inspired by GoLang's response and error parsing functionality at the same time. This package provide with a datatype that can we used to return data and exception from a function call at the same time. To provide the flexibility with the datatype of the data field in the object you can strongly couple the object to store a specific type of value by using a TypedConstructor.

🛠Features #

  • return a data variable and exception from a function at the same time.
  • make data strongly coupled to store in particular datatype value only.
  • provide the ability to return multiple parameters which isn't supported in dart.

⚡️Getting started #

🎖Installation #

In the dependencies: section of your pubspec.yaml, add the following line:

dependencies:
  function_call_outcome: ^0.0.2

Than import the package via:

import 'package:function_call_outcome/function_call_outcome.dart';

🎮Usage #

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

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

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

class _MyAppState extends State<MyApp> {
  bool isCallAsync = false;
  int count = -1;
  late CallOutcome<String> result;

  Future<CallOutcome<String>> functionAsync()async{
      Future.delayed(const Duration(milliseconds: 1500),(){
      });
      return CallOutcome(data: "Hello world from async");
  }

  CallOutcome<String> function(){
      setState((){
        count++;
      });
    print(count);
      if(count%2==0){
          return CallOutcome<String>(data: "Hello world from sync");
      }else{
          return CallOutcome<String>(exception: Exception("Hello world"));
      }
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Text(count == -1?"Start":result.data??result.exception.toString())
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async{
              if(isCallAsync){
                result = await functionAsync();
              }else{
                result = function();
              }
              setState((){
                isCallAsync = !isCallAsync;
              });

          },
          child: const Icon(Icons.reply),
          backgroundColor: Colors.green,
        ),
      ),
    );
  }
}

☀️Created and Maintained by: #

Developed by:


CyberWake

🐛Issues & Feedback #

Please file an issue! to send feedback or report a bug. Thank you!

5
likes
140
pub points
56%
popularity

Publisher

verified publisher iconcyberwake.me

A dart package to simplify return data and exception from a function call

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_call_outcome