smart_text_widget 0.0.2+7 copy "smart_text_widget: ^0.0.2+7" to clipboard
smart_text_widget: ^0.0.2+7 copied to clipboard

A custom Flutter text widget that handles null values, empty strings, lists, maps, and numeric values. Supports truncation, scrolling, and error handling.

example/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'RTText Widget Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('RTText Widget Showcase'),
        ),
        body: const SingleChildScrollView(
          child: Padding(
            padding: EdgeInsets.all(12.0),
            child: RTTextShowcase(),
          ),
        ),
      ),
    );
  }
}

class RTTextShowcase extends StatelessWidget {
  const RTTextShowcase({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: const [
        Text(
          'ResearchThinker Smart Text Widget: Handles Null, Empty, List, and Map values.',
          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 10),
        // Null Value Example
        RTText(
          text: null,
          errorTrue: true,
          errorValue: "Null Value Encountered!",
          truncateEnable: true,
          truncateSize: 10,
          customEllipsis: "-->",
          maxWidth: true,
        ),
        SizedBox(height: 10),
        RTText(
          // Empty String Example
          text: "",
          errorTrue: true,
          errorValue: "Empty String!",
          maxWidth: true,
        ),
        SizedBox(height: 10),
        RTText(
          // Zero Value Example
          text: "0.0",
          truncateEnable: true,
          truncateSize: 4,
          textAlign: TextAlign.center,
          maxWidth: true,
          customEllipsis: " ==> ",
        ),
        SizedBox(height: 10),
        RTText(
          // List Example with Separator
          text: ["Apple", "Banana", "Cherry"],
          scroll: true,
          listSeparator: " | ",
          textAlign: TextAlign.center,
          textStyle: TextStyle(
              fontSize: 16, color: Colors.blue, fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 10),
        RTText(
          text: ["Apple", "Banana", "Cherry"],
          scroll: true,
          listSeparator: " , ",
          textAlign: TextAlign.center,
          textStyle: TextStyle(
              fontSize: 16, color: Colors.blue, fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 10),
        RTText(
          text: ["Apple", "Banana", "Cherry"],
          scroll: true,
          listSeparator: " - ",
          textAlign: TextAlign.center,
          textStyle: TextStyle(
              fontSize: 16, color: Colors.blue, fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 10),
        RTText(
          // Map Example
          text: {
            "name": "ResearchThinker",
            "website": "https://researchthinker.com"
          },
          errorTrue: false,
          maxWidth: true,
          emptyPlaceholder: "No data available",
          textAlign: TextAlign.right,
        ),
        SizedBox(height: 10),
        RTText(
          // Dynamic Value Example
          text: 120,
          textStyle: TextStyle(color: Colors.green, fontSize: 18),
          textAlign: TextAlign.left,
          maxWidth: true,
        ),
        SizedBox(height: 10),
        RTText(
          // Large String with Scroll and Max Width
          text:
              "This is a very long text that might not fit in a single line and needs to be scrolled or truncated.",
          scroll: true,
          maxWidth: true,
          truncateSize: 62,
          truncateEnable: true,
          textStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.w400),
          textAlign: TextAlign.justify,
        ),
      ],
    );
  }
}
1
likes
160
pub points
27%
popularity

Publisher

unverified uploader

A custom Flutter text widget that handles null values, empty strings, lists, maps, and numeric values. Supports truncation, scrolling, and error handling.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on smart_text_widget