Last updated:
0 purchases
flutter call outcome
function_call_outcome #
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
copied to clipboard
Than import the package via:
import 'package:function_call_outcome/function_call_outcome.dart';
copied to clipboard
🎮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,
),
),
);
}
}
copied to clipboard
☀️Created and Maintained by: #
Developed by:
CyberWake
🐛Issues & Feedback #
Please file an issue! to send feedback or report a bug. Thank you!
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.