view static method

Widget view(
  1. Widget child, {
  2. Color? bgColor,
  3. Color? txtColor,
  4. Future<void>? func,
  5. String watermarkTxt = '',
  6. bool watermarkColorful = false,
})

Implementation

static Widget view(
  final Widget child, {
  final Color? bgColor,
  final Color? txtColor,
  final Future<void>? func,
  final String watermarkTxt = '',
  final bool watermarkColorful = false,
}) {
  indexCharTimer = Timer.periodic(
    const Duration(milliseconds: 25),
    (final Timer timer) => indexChar.value = indexChar.value > 0xE076 ? 0xE000 : indexChar.value + 1,
  );
  indexDotTimer = Timer.periodic(
    const Duration(milliseconds: 500),
    (final Timer timer) => indexDot.value = (indexDot.value.length > 2) ? '' : '${indexDot.value}.',
  );
  return Directionality(
    textDirection: TextDirection.ltr,
    child: Stack(
      children: [
        RepaintBoundary(
          child: FutureBuilder(
            future: func,
            builder: (final _, final snapshot) =>
                snapshot.connectionState == ConnectionState.done ? child : const SizedBox.shrink(),
          ),
        ),
        ValueListenableBuilder(
          valueListenable: ok,
          builder: (final _, final bool ok, final __) => AnimatedSwitcher(
            duration: const Duration(milliseconds: 300),
            child: ok
                ? const SizedBox.shrink()
                : Builder(
                    key: const ValueKey('nga_splash_view'),
                    builder: (final ctx) {
                      final isDarkMode = MediaQuery.of(ctx).platformBrightness == Brightness.dark;
                      final targetBgColor =
                          bgColor ?? (isDarkMode ? const Color(0xFF000000) : const Color(0xFFF8F8F8));
                      final targetTxtColor =
                          txtColor ?? (isDarkMode ? const Color(0xFFF8F8F8) : const Color(0xFF000000));
                      final targetTxtStyle =
                          TextStyle(fontFamily: 'BOOT', package: 'nga_sdk', color: targetTxtColor);
                      return Container(
                        color: targetBgColor,
                        alignment: Alignment.center,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            ValueListenableBuilder(
                              valueListenable: indexChar,
                              builder: (final _, final int char, final __) => Text(
                                String.fromCharCode(char),
                                style: targetTxtStyle.copyWith(fontSize: 40),
                              ),
                            ),
                            const SizedBox(height: 10),
                            ValueListenableBuilder(
                              valueListenable: indexDot,
                              builder: (final _, final String dot, final __) =>
                                  Text('Loading$dot', style: targetTxtStyle.copyWith(fontSize: 20)),
                            ),
                          ],
                        ),
                      );
                    },
                  ),
          ),
        ),
        if (watermarkTxt.isNotEmpty)
          Builder(
            builder: (final ctx) => NGAWatermark.get(ctx, watermarkTxt, colorful: watermarkColorful),
          ),
      ],
    ),
  );
}