import 'package:flutter/material.dart';
import 'package:flut/flut/runtime.dart';

class FlutText {
  FlutText._();

  static Text? flutDecode(FlutRuntime runtime, Map<String, dynamic> data) {
    final textSpan = runtime.unpackOptionalField<InlineSpan>(data, 'textSpan');
    if (textSpan != null) {
      return Text.rich(
        textSpan,
        key: runtime.decodeKey(data),
        style: runtime.unpackOptionalField<TextStyle>(data, 'style'),
        textAlign: runtime.unpackOptionalField<TextAlign>(data, 'textAlign'),
        softWrap: runtime.unpackOptionalField<bool>(data, 'softWrap'),
        maxLines: runtime.unpackOptionalField<int>(data, 'maxLines'),
        overflow: runtime.unpackOptionalField<TextOverflow>(data, 'overflow'),
      );
    }
    return Text(
      runtime.unpackRequiredField<String>(data, 'data'),
      key: runtime.decodeKey(data),
      style: runtime.unpackOptionalField<TextStyle>(data, 'style'),
      textAlign: runtime.unpackOptionalField<TextAlign>(data, 'textAlign'),
      softWrap: runtime.unpackOptionalField<bool>(data, 'softWrap'),
      maxLines: runtime.unpackOptionalField<int>(data, 'maxLines'),
      overflow: runtime.unpackOptionalField<TextOverflow>(data, 'overflow'),
    );
  }
}
