Flutter Dart: Rendering a widget with Listview error

I’m creating an app with Bluetooth connection and it’s having errors while creating a widget with a list that I created to put all Bluetooth devices connect. Looks like the Flutter is trying to create an infinite widget, please someone can help me? I don’t know how to solve it. The code below is from the Bluetooth screen that is linked to the settings in the main.dart menu:

import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';

class BluetoothScreen extends StatefulWidget {
  @override
  _BluetoothScreenState createState() => _BluetoothScreenState();
}

class _BluetoothScreenState extends State<BluetoothScreen> {
  List<BluetoothDevice> devicesList = [];
  BluetoothDevice? connectedDevice;
  bool isScanning = false;

  @override
  void initState() {
    super.initState();
    scanForDevices();
  }

  void scanForDevices() async {
    setState(() {
      isScanning = true;
      devicesList.clear();
    });

    FlutterBluePlus.startScan(timeout: Duration(seconds: 4));

    FlutterBluePlus.scanResults.listen((results) {
      setState(() {
        devicesList = results.map((r) => r.device).toList();
      });
    });

    await Future.delayed(Duration(seconds: 4));
    FlutterBluePlus.stopScan();
    setState(() {
      isScanning = false;
    });
  }

  void connectToDevice(BluetoothDevice device) async {
    await device.connect();
    setState(() {
      connectedDevice = device;
    });
  }

  void disconnectFromDevice() async {
    if (connectedDevice != null) {
      await connectedDevice!.disconnect();
      setState(() {
        connectedDevice = null;
      });
    }
  }

@override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        if (isScanning)
          Flexible(
            child: Center(child: CircularProgressIndicator()),
          )
        else
          Flexible(
            child: devicesList.isEmpty
                ? Center(child: Text('Nenhum dispositivo encontrado'))
                : ListView.builder(
                    itemCount: devicesList.length,
                    itemBuilder: (context, index) {
                      final device = devicesList[index];
                      return ListTile(
                        title: Text(device.name.isNotEmpty
                            ? device.name
                            : 'Dispositivo sem nome'),
                        subtitle: Text(device.id.toString()),
                        onTap: () {
                          connectToDevice(device);
                        },
                      );
                    },
                  ),
          ),
        if (connectedDevice != null)
          Padding(
            padding: const EdgeInsets.all(10.0),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text('Conectado a ${connectedDevice!.name}'),
                ElevatedButton(
                  onPressed: disconnectFromDevice,
                  child: Text('Desconectar'),
                ),
              ],
            ),
          ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: ElevatedButton(
            onPressed: scanForDevices,
            child: Text('Escanear Dispositivos'),
          ),
        ),
      ],
    );
  }
}

This is what appears when I try debug it:

The relevant error-causing widget was:
    Column Column:file:///C:/Users/marco/Desktop/projetos/Aplicativo%20Apollodi/base_apollodi/lib/screens/bluetooth_screen.dart:59:12

When the exception was thrown, this was the stack:
The following RenderObject was being processed when the exception was fired: RenderFlex#68e4a relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
    constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
    size: MISSING
    direction: vertical
    mainAxisAlignment: start
    mainAxisSize: max
    crossAxisAlignment: center
    verticalDirection: down
    child 1: RenderPositionedBox#34313 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.loose
        constraints: MISSING
        size: MISSING
        alignment: Alignment.center
        textDirection: ltr
        widthFactor: expand
        heightFactor: expand
        child: RenderSemanticsAnnotations#12ee4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: offset=Offset(0.0, 0.0)
            constraints: MISSING
            size: MISSING
            child: RenderConstrainedBox#4c22a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                additionalConstraints: BoxConstraints(36.0<=w<=Infinity, 36.0<=h<=Infinity)
                child: RenderCustomPaint#bdea4 NEEDS-LAYOUT NEEDS-PAINT
                    parentData: <none>
                    constraints: MISSING
                    size: MISSING
                    painter: _CircularProgressIndicatorPainter#043bd()
    child 2: RenderPadding#39626 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
        constraints: MISSING
        size: MISSING
        padding: EdgeInsets.all(8.0)
        textDirection: ltr
        child: RenderSemanticsAnnotations#a3624 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: offset=Offset(0.0, 0.0)
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#894c9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#5ee88 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(64.0<=w<=Infinity, 40.0<=h<=Infinity)
RenderObject: RenderFlex#68e4a relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
    constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
    size: MISSING
    direction: vertical
    mainAxisAlignment: start
    mainAxisSize: max
    crossAxisAlignment: center
    verticalDirection: down
    child 1: RenderPositionedBox#34313 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.loose
        constraints: MISSING
        size: MISSING
        alignment: Alignment.center
        textDirection: ltr
        widthFactor: expand
        heightFactor: expand
        child: RenderSemanticsAnnotations#12ee4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: offset=Offset(0.0, 0.0)
            constraints: MISSING
            size: MISSING
            child: RenderConstrainedBox#4c22a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                additionalConstraints: BoxConstraints(36.0<=w<=Infinity, 36.0<=h<=Infinity)
                child: RenderCustomPaint#bdea4 NEEDS-LAYOUT NEEDS-PAINT
                    parentData: <none>
                    constraints: MISSING
                    size: MISSING
                    painter: _CircularProgressIndicatorPainter#043bd()
    child 2: RenderPadding#39626 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
        constraints: MISSING
        size: MISSING
        padding: EdgeInsets.all(8.0)
        textDirection: ltr
        child: RenderSemanticsAnnotations#a3624 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: offset=Offset(0.0, 0.0)
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#894c9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#5ee88 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(64.0<=w<=Infinity, 40.0<=h<=Infinity)
════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderFlex#47094 relayoutBoundary=up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 2165 pos 12: 'hasSize'
The relevant error-causing widget was:

I tried to modify the column with an expanded, with a flexible, but nothing worked

New contributor

marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật