div_expressions_resolver 0.4.2 copy "div_expressions_resolver: ^0.4.2" to clipboard
div_expressions_resolver: ^0.4.2 copied to clipboard

DivKit expressions resolver plugin for Flutter. Wraps native iOS and Android implementations to resolve expressions with variables, operators, and functions.

div_expressions_resolver #

Pub DivKit expressions resolver plugin for Flutter client.

Overview #

This library provides a wrapper around native implementation of ExpressionResolver for iOS and Evaluator for Android.

Features #

The calculated part of the expression is written using the @{} construction and may contain variables, operators, and functions.

Calculated expressions support the following constructions:

  • Logical operators: ==, !=, !, >, >=, <, =, &&, ||.
  • Arithmetic operators: +, -, *, /, %.
  • Ternary operator: counter > 0 ? true : false.
  • Grouping logical expressions: logging_enabled && (user_name == 'John' || user_email != '').
  • Function calls: mult(total_price, .83)
  • Using calculated parts within strings and string-type calculated expressions: "mail: @{'@{username}@ya.ru'}" is converted to mail: john@ya.ru

So fully supports of DivKit specification:

Usage #

    final nativeResolver = NativeDivExpressionsResolver();
    
    // Use simple math
    fianl r1 = await nativeResolver.resolve( // Result: 1
        "@{0 + 1}",
        context: {},
    );

    // Use variables
    fianl r2 = await nativeResolver.resolve( // Result: 2
        "@{a + b}",
        context: {
            "a" : 1,
            "b" : 1,
        },
    );

    // Use embedded functions
    fianl r3 = await nativeResolver.resolve( // Result: 3
        "@{sum(a, b)}",
        context: {
            "a" : 1,
            "b" : 2,
        },
    );
    
    // Use branching and more!
    fianl r3 = await nativeResolver.resolve( // Result: 4
        "@{sum(a, b) == 5 ? 4 : 0}",
        context: {
            "a" : 3,
            "b" : 2,
        },
    );
4
likes
130
pub points
30%
popularity

Publisher

verified publisherdivkit.tech

DivKit expressions resolver plugin for Flutter. Wraps native iOS and Android implementations to resolve expressions with variables, operators, and functions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on div_expressions_resolver