Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.6 kB
4
Indexable
Never
              listData.add(barcode.barcodes.first.rawValue ?? "");
            });
          },
        ),
        Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            alignment: Alignment.bottomCenter,
            height: 100,
            color: Colors.black.withOpacity(0.4),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                ValueListenableBuilder(
                  valueListenable: controller.hasTorchState,
                  builder: (context, state, child) {
                    if (state != true) {
                      return const SizedBox.shrink();
                    }
                    return IconButton(
                      color: Colors.white,
                      icon: ValueListenableBuilder<TorchState>(
                        valueListenable: controller.torchState,
                        builder: (context, state, child) {
                          switch (state) {
                            case TorchState.off:
                              return const Icon(
                                Icons.flash_off,
                                color: Colors.grey,
                              );
                            case TorchState.on:
                              return const Icon(
                                Icons.flash_on,
                                color: Colors.yellow,
                              );
                          }
                        },
                      ),
                      iconSize: 32.0,
                      onPressed: () => controller.toggleTorch(),
                    );
                  },
                ),
                IconButton(
                  color: Colors.white,
                  icon: isStarted
                      ? const Icon(Icons.stop)
                      : const Icon(Icons.play_arrow),
                  iconSize: 32.0,
                  onPressed: _startOrStop,
                ),
                Center(
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width - 200,
                    height: 50,
                    child: FittedBox(
                      child: Text(
                        barcode?.barcodes.first.rawValue ??
                            'Scan something!',
                        overflow: TextOverflow.fade,
                        style: Theme.of(context)
                            .textTheme
                            .headlineMedium!
                            .copyWith(color: Colors.white),
                      ),
                    ),
                  ),
                ),
                IconButton(
                  color: Colors.white,
                  icon: ValueListenableBuilder<CameraFacing>(
                    valueListenable: controller.cameraFacingState,
                    builder: (context, state, child) {
                      switch (state) {
                        case CameraFacing.front:
                          return const Icon(Icons.camera_front);
                        case CameraFacing.back:
                          return const Icon(Icons.camera_rear);
                      }
                    },
                  ),
                  iconSize: 32.0,
                  onPressed: (numberOfCameras ?? 0) < 2
                      ? null
                      : () => controller.switchCamera(),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  },
);
Leave a Comment