-2

I need to add Semantics value to all Text Widgets, Is there a way to do it automatically, to avoid manual addition?

1
  • first try to find a way to do anything before direct ask? Commented Dec 18, 2023 at 20:10

1 Answer 1

1

There is no automatic way, but you can make your own text input that wraps a flutter text and reuse it. Here is a base example:

import 'package:flutter/material.dart';

class SemanticTextField extends StatelessWidget {
  final String semanticLabel;

  final Function(String)? onChanged;
  const SemanticTextField({
    Key? key,
    required this.semanticLabel,
    this.onChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Semantics(
      container: true,
      textField: true,
      label: semanticLabel,
      child: TextFormField(
        onChanged: onChanged,
      ),
    );
  }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.