admin 管理员组

文章数量: 1086019

I'm working on a Flutter app targeting Android and iOS, using Flutter 3.29.0. I've received user reports of a rendering glitch on a screen containing a ListView. The problem is reported to appear to multiple users using the same phone Samsung A51 5G.

The text inside the ListTile in the ListView is not rendered correctly, as you can see in this image

I've only encountered a similar problem with the app running in debug mode on a Xiaomi Note 11S, but this time the problem is presenting itself with the app built in release mode.

Any idea what could be the cause of this?

The structure of the Widget tree is as follows: ChiamateListScreen -> TabBarView -> ChiamateListTab -> ListView -> ChiamateListItem

Code for ChiamateListScreen

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../../service_locator.dart';
import '../../../../../theme.dart';
import '../../../../extensions/build_context_x.dart';
import '../../../common/widgets/dismissable_keyboard.dart';
import '../../../common/widgets/padded_tab.dart';
import '../../../common/widgets/tecnici_app_bar.dart';
import '../bloc/chiamate_list_bloc.dart';
import '../widgets/chiamate_list_tab.dart';

class ChiamateListScreen extends StatefulWidget {
  const ChiamateListScreen({super.key});

  @override
  State<ChiamateListScreen> createState() => _ChiamateListScreenState();
}

class _ChiamateListScreenState extends State<ChiamateListScreen>
    with SingleTickerProviderStateMixin {
  late ChiamateListBloc chiamateListBloc;
  late TabController _tabController;
  late int _activeTab;

  @override
  void initState() {
    super.initState();
    _activeTab = 0;
    _tabController = TabController(
      length: 3,
      vsync: this,
    );
    _tabController.addListener(_onTabChanged);

    chiamateListBloc = serviceLocator();
  }

  void _onTabChanged() {
    if (!_tabController.indexIsChanging && _activeTab != _tabController.index) {
      _activeTab = _tabController.index;
    }
  }

  @override
  void dispose() {
    _tabController.removeListener(_onTabChanged);
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return DismissableKeyboard(
      child: BlocProvider<ChiamateListBloc>.value(
        value: chiamateListBloc..add(const ChiamateListStarted()),
        child: BlocListener<ChiamateListBloc, ChiamateListState>(
          listener: (context, state) {
            if (state.isError) {
              context.showError(message: state.errorMessage);
            }
          },
          child: Scaffold(
            appBar: TecniciAppBar(
              title: 'home.dashboard.calls'.tr(),
              bottom: TabBar(
                dividerColor: Colors.transparent,
                indicatorSize: TabBarIndicatorSize.label,
                isScrollable: true,
                padding: EdgeInsets.zero,
                indicatorPadding: EdgeInsets.zero,
                labelPadding: EdgeInsets.zero,
                indicatorWeight: 4,
                controller: _tabController,
                tabAlignment: TabAlignment.start,
                indicator: const BoxDecoration(
                  color: MobileLiftColors.neutralLight,
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(8),
                    topRight: Radius.circular(8),
                  ),
                ),
                unselectedLabelColor: MobileLiftColors.neutral,
                labelStyle: Theme.of(context).textTheme.titleMedium,
                tabs: [
                  PaddedTab(title: 'call.to_accept'.tr()),
                  PaddedTab(title: 'call.in_progress'.tr()),
                  PaddedTab(title: 'call.suspended'.tr()),
                ],
              ),
            ),
            body: BlocBuilder<ChiamateListBloc, ChiamateListState>(
              builder: (context, state) {
                return TabBarView(
                  controller: _tabController,
                  children: [
                    ChiamateListTab.init(calls: state.callsToAccept),
                    ChiamateListTab.init(calls: state.callsInProgress),
                    ChiamateListTab.init(calls: state.suspendedCalls),
                  ],
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}

I'm working on a Flutter app targeting Android and iOS, using Flutter 3.29.0. I've received user reports of a rendering glitch on a screen containing a ListView. The problem is reported to appear to multiple users using the same phone Samsung A51 5G.

The text inside the ListTile in the ListView is not rendered correctly, as you can see in this image

I've only encountered a similar problem with the app running in debug mode on a Xiaomi Note 11S, but this time the problem is presenting itself with the app built in release mode.

Any idea what could be the cause of this?

The structure of the Widget tree is as follows: ChiamateListScreen -> TabBarView -> ChiamateListTab -> ListView -> ChiamateListItem

Code for ChiamateListScreen

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../../service_locator.dart';
import '../../../../../theme.dart';
import '../../../../extensions/build_context_x.dart';
import '../../../common/widgets/dismissable_keyboard.dart';
import '../../../common/widgets/padded_tab.dart';
import '../../../common/widgets/tecnici_app_bar.dart';
import '../bloc/chiamate_list_bloc.dart';
import '../widgets/chiamate_list_tab.dart';

class ChiamateListScreen extends StatefulWidget {
  const ChiamateListScreen({super.key});

  @override
  State<ChiamateListScreen> createState() => _ChiamateListScreenState();
}

class _ChiamateListScreenState extends State<ChiamateListScreen>
    with SingleTickerProviderStateMixin {
  late ChiamateListBloc chiamateListBloc;
  late TabController _tabController;
  late int _activeTab;

  @override
  void initState() {
    super.initState();
    _activeTab = 0;
    _tabController = TabController(
      length: 3,
      vsync: this,
    );
    _tabController.addListener(_onTabChanged);

    chiamateListBloc = serviceLocator();
  }

  void _onTabChanged() {
    if (!_tabController.indexIsChanging && _activeTab != _tabController.index) {
      _activeTab = _tabController.index;
    }
  }

  @override
  void dispose() {
    _tabController.removeListener(_onTabChanged);
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return DismissableKeyboard(
      child: BlocProvider<ChiamateListBloc>.value(
        value: chiamateListBloc..add(const ChiamateListStarted()),
        child: BlocListener<ChiamateListBloc, ChiamateListState>(
          listener: (context, state) {
            if (state.isError) {
              context.showError(message: state.errorMessage);
            }
          },
          child: Scaffold(
            appBar: TecniciAppBar(
              title: 'home.dashboard.calls'.tr(),
              bottom: TabBar(
                dividerColor: Colors.transparent,
                indicatorSize: TabBarIndicatorSize.label,
                isScrollable: true,
                padding: EdgeInsets.zero,
                indicatorPadding: EdgeInsets.zero,
                labelPadding: EdgeInsets.zero,
                indicatorWeight: 4,
                controller: _tabController,
                tabAlignment: TabAlignment.start,
                indicator: const BoxDecoration(
                  color: MobileLiftColors.neutralLight,
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(8),
                    topRight: Radius.circular(8),
                  ),
                ),
                unselectedLabelColor: MobileLiftColors.neutral,
                labelStyle: Theme.of(context).textTheme.titleMedium,
                tabs: [
                  PaddedTab(title: 'call.to_accept'.tr()),
                  PaddedTab(title: 'call.in_progress'.tr()),
                  PaddedTab(title: 'call.suspended'.tr()),
                ],
              ),
            ),
            body: BlocBuilder<ChiamateListBloc, ChiamateListState>(
              builder: (context, state) {
                return TabBarView(
                  controller: _tabController,
                  children: [
                    ChiamateListTab.init(calls: state.callsToAccept),
                    ChiamateListTab.init(calls: state.callsInProgress),
                    ChiamateListTab.init(calls: state.suspendedCalls),
                  ],
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}

Code for ChiamateListTab

// ignore_for_file: use_build_context_synchronously

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

import '../../../../../repositories/dto/call_on_list_dto/call_on_list_dto.dart';
import '../../../../../routes.dart';
import '../../../../../services/navigation_service.dart';
import '../../../../../theme.dart';
import '../../../common/widgets/tecnici_loader_blue.dart';
import '../../../common/widgets/tecnici_no_results.dart';
import '../bloc/chiamate_list_bloc.dart';
import 'chiamate_list_item.dart';

class ChiamateListTab extends StatelessWidget {
  final List<CallOnListDto> calls;
  final GlobalKey<RefreshIndicatorState> chiamateRefreshIndicatorKey;

  const ChiamateListTab({
    required this.calls,
    required this.chiamateRefreshIndicatorKey,
    super.key,
  });

  static ChiamateListTab init({
    required List<CallOnListDto> calls,
  }) =>
      ChiamateListTab(
        calls: calls,
        chiamateRefreshIndicatorKey: GlobalKey<RefreshIndicatorState>(),
      );

  @override
  Widget build(BuildContext context) {
    return BlocConsumer<ChiamateListBloc, ChiamateListState>(
      listener: (context, state) {
        if (state.isRefreshing) {
          chiamateRefreshIndicatorKey.currentState!.show();
        }
      },
      builder: (context, state) => state.isLoading
          ? const Center(child: TecniciLoaderBlue())
          : LayoutBuilder(
              builder: (context, constraints) => RefreshIndicator(
                key: chiamateRefreshIndicatorKey,
                color: MobileLiftColors.primaryBlue,
                triggerMode: RefreshIndicatorTriggerMode.anywhere,
                onRefresh: () async {
                  Future bloc = context.read<ChiamateListBloc>().stream.first;
                  context
                      .read<ChiamateListBloc>()
                      .add(const ChiamateListRefreshRequested());
                  await bloc;
                },
                child: calls.isEmpty
                    ? SingleChildScrollView(
                        physics: const AlwaysScrollableScrollPhysics(),
                        child: ConstrainedBox(
                          constraints:
                              BoxConstraints(minHeight: constraints.maxHeight),
                          child: const Center(
                            child: TecniciNoResults(),
                          ),
                        ),
                      )
                    : ListView.separated(
                        padding: const EdgeInsets.all(8),
                        separatorBuilder: (context, index) =>
                            const SizedBox(height: 8),
                        itemCount: calls.length,
                        itemBuilder: (BuildContext context, int index) =>
                            ChiamateListItem(
                          chiamata: calls[index],
                          onTap: () async {
                            await NavigationService().pushNamed(
                              Routes.chiamataDetail,
                              arguments: {
                                'chiamataId': calls[index].id,
                              },
                            );

                            Map<String, dynamic>? arguments =
                                ModalRoute.of(context)?.settings.arguments
                                    as Map<String, dynamic>?;

                            bool? refresh = arguments?['refreshChiamateList'];

                            if (refresh ?? false) {
                              context
                                  .read<ChiamateListBloc>()
                                  .add(const ChiamateListStarted());

                              arguments?['refreshChiamateList'] = false;
                            }
                          },
                        ),
                      ),
              ),
            ),
    );
  }
}

Code for ChiamateListItem

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

import '../../../../../repositories/dto/call_on_list_dto/call_on_list_dto.dart';
import '../../../../../theme.dart';
import '../../../../extensions/datetime_extension.dart';
import '../../../../extensions/string_extensions.dart';

typedef ChiamataListItemCallback = void Function();

class ChiamateListItem extends StatelessWidget {
  final CallOnListDto chiamata;
  final ChiamataListItemCallback onTap;

  const ChiamateListItem({
    required this.chiamata,
    required this.onTap,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return ListTile(
      dense: true,
      tileColor: chiamata.isInLavorazione ? Colors.yellowAccent : Colors.white,
      shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(8))),
      onTap: onTap,
      title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: Text(
              chiamata.statoChiamataCodice != null
                  ? chiamata.statoChiamataCodice!.asString().capitalize()
                  : 'common.undefined'.tr(),
              style: Theme.of(context).textTheme.labelLarge,
            ),
          ),
          Text(
            chiamata.dataOra.formatDateTimeString(),
            style: Theme.of(context).textTheme.bodyMedium,
          ),
        ],
      ),
      subtitle: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            chiamata.impianto?.indirizzo.formattedAddress() ??
                'common.undefined'.tr(),
            style: Theme.of(context).textTheme.bodyMedium,
          ),
          Text(
            chiamata.impianto?.descrizione ?? 'common.undefined'.tr(),
            style: Theme.of(context).textTheme.bodyMedium,
          ),
          Text(
            chiamata.problemaDescrizione ?? 'common.undefined'.tr(),
            style: Theme.of(context).textTheme.bodyMedium,
          ),
          Text(
            chiamata.descrizioneAggiuntivaProblema ?? 'common.undefined'.tr(),
            style: Theme.of(context).textTheme.bodyMedium,
          ),
          Row(
            children: [
              Expanded(
                child: Text(
                  '${'common.technician'.tr()}: ${chiamata.tecnico?.nome ?? ''} ${chiamata.tecnico?.cognome ?? ''}',
                  style: Theme.of(context).textTheme.bodyMedium,
                ),
              ),
              if (chiamata.numeroSolleciti > 0)
                Badge(
                  offset: const Offset(0, 0),
                  isLabelVisible: chiamata.numeroSolleciti > 0,
                  backgroundColor: MobileLiftColors.accent,
                  label: Text(
                    '${'call.solicitations'.tr()}: ${chiamata.numeroSolleciti.toString()}',
                    style: Theme.of(context).textTheme.labelLarge!.copyWith(
                          color: Colors.white,
                        ),
                  ),
                ),
            ],
          ),
        ],
      ),
    );
  }
}

Share Improve this question asked Mar 28 at 16:26 Marina P.Marina P. 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Please update to 3.29.1 which is a hotfix for this and some other issues as well detailed here.

本文标签: Flutter rendering glitch on ListView (Flutter 3290)Stack Overflow