init static method
Initializing the library.
We define a list of bad words (censorWords) that you want to censor.
We use the replaceAllMapped method to replace each occurrence of a bad word in the text with asterisks of the same length as the bad word.
It prints the text with the bad words (censorWords) replaced by asterisks.
Implementation
static Future<void> init(BuildContext context,
{Size designSize = defaultSize,
bool splitScreenMode = false,
ThemeData? defaultTheme,
List<String>? censorWords,
bool minTextAdapt = false,
bool scaleByHeight = false}) async {
final mediaQueryContext =
context.getElementForInheritedWidgetOfExactType<MediaQuery>();
final initCompleter = Completer<void>();
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((_) {
mediaQueryContext?.visitChildElements((el) => data._context = el);
if (data._context != null) initCompleter.complete();
});
final deviceData = MediaQuery.maybeOf(context).nonEmptySizeOrNull();
final deviceSize = deviceData?.size ?? designSize;
final orientation = deviceData?.orientation ??
(deviceSize.width > deviceSize.height
? Orientation.landscape
: Orientation.portrait);
data
..blockedWords = censorWords
.._context = scaleByHeight ? null : context
.._uiSize = designSize
.._themeData = defaultTheme ?? Theme.of(context)
.._splitScreenMode = splitScreenMode
.._minTextAdapt = minTextAdapt
.._orientation = orientation
.._screenWidth = scaleByHeight
? (deviceSize.height * designSize.width) / designSize.height
: deviceSize.width
.._screenHeight = deviceSize.height;
data._elementsToRebuild?.forEach((el) => el.markNeedsBuild());
return initCompleter.future;
}