build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds the scaffold for the receive screen.

The scaffold contains a center widget that contains a column of widgets. The column contains a QR code scanner if _showScanner is true, otherwise it contains a text field for entering the transfer name. Below the text field is an elevated button for initiating the receive process.

Implementation

@override
Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Constants.backColor,
    body: Center(
        child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // If _showScanner is false, display a QR code icon that can be tapped
        // to start the QR code scanner.
        if (!_showScanner)
          GestureDetector(
            onTap: () {
              if (Platform.isIOS || Platform.isAndroid) {
                setState(() {
                  _showScanner = true;
                });
              }
            },
            child: Container(
              width: 200,
              height: 200,
              decoration: const BoxDecoration(
                shape: BoxShape.circle,
                color: Constants.textColor,
              ),
              child: const Center(
                child: Icon(
                  Icons.qr_code,
                  color: Constants.highlightColor,
                  size: 100,
                ),
              ),
            ),
          ),
        // If _showScanner is true, display the QR code scanner.
        if (_showScanner)
          Container(
            width: MediaQuery.of(context).size.width * 0.8,
            height: MediaQuery.of(context).size.height * 0.5,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(16),
            ),
            child: _buildQRScanner(),
          ),
        // Add some spacing between the scanner and the text field.
        const SizedBox(height: 32),
        // Display a text field for entering the transfer name.
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: SizedBox(
            width: MediaQuery.of(context).size.width * 0.5,
            child: TextField(
              controller: myController,
              textAlign: TextAlign.center,
              style: const TextStyle(
                color: Constants.highlightColor,
              ),
              onChanged: (value) {
                setState(() {
                  inputValue = value;
                });
              },
              decoration: const InputDecoration(
                labelText: 'Enter Transfername',
                alignLabelWithHint: true,
                floatingLabelAlignment: FloatingLabelAlignment.center,
                labelStyle: TextStyle(color: Constants.textColor),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Constants.textColor),
                ),
                focusedBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Constants.textColor),
                ),
              ),
            ),
          ),
        ),
        // Add some spacing between the text field and the receive button.
        const SizedBox(height: 16),
        // Display an elevated button for initiating the receive process.
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            backgroundColor: Constants.textColor,
            foregroundColor: Constants.backColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(20),
            ),
          ),
          onPressed: () {
            loadSettings().then((_) => _startTransfer(appOrigin));
          },
          child: const Text('Receive'),
        ),
      ],
    )),
  );
}