iamSahdeep / seo_renderer

A Flutter Web Plugin to display Text Widget as Html for SEO purpose
MIT License
114 stars 15 forks source link

Range Error (index) when using TextRenderer inside a List #17

Closed felipesses closed 2 years ago

felipesses commented 2 years ago

Hello, I'm trying to fetch an list of names and it keeps getting error of index when using ListView or Column to map a List, here's the example page

import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:flutter_web_poc/presentation/controllers/seo/seo_controller.dart';
import 'package:seo_renderer/seo_renderer.dart';

class SeoPage extends StatefulWidget {
  const SeoPage({Key? key}) : super(key: key);

  @override
  State<SeoPage> createState() => _SeoPageState();
}

class _SeoPageState extends State<SeoPage> {
  final controller = Modular.get<SeoController>();

  @override
  void initState() {
    super.initState();
    controller.fetchAllTodos();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const TextRenderer(
          child: Text('Seo Page'),
        ),
      ),
      body: AnimatedBuilder(
        animation: controller,
        builder: (context, widget) {
          return ListView.builder(
            itemCount: controller.todos.length,
            itemBuilder: (context, index) {
              final todo = controller.todos[index];
              return ListTile(
                title: TextRenderer(
                  style: TextRendererStyle.header1,
                  child: Text(
                    todo.title,
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}

Here's my RobotDetector widget, it seems to me that nothing is wrong with it

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Modular.setObservers(
        [seoRouteObserver]); // replacement for navigatorObservers
    return RobotDetector(
      debug: true,
      child: MaterialApp.router(
        title: 'Flutter Web Poc',
        routeInformationParser: Modular.routeInformationParser,
        routerDelegate: Modular.routerDelegate,
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}

Error Message:

The following IndexError was thrown during a scheduler callback:
RangeError (index): Index out of range: index must not be negative: -12

When the exception was thrown, this was the stack
dart-sdk[/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart]() 251:49  throw_
dart-sdk[/lib/_internal/js_dev_runtime/private/js_array.dart]() 581:7 _get]
lib[/_engine/engine/canvaskit/embedded_views.dart]() 647:52 [_updateOverlays] 
packages[/flutter/src/rendering/binding.dart]() 501:18                            drawFrame
packages[/flutter/src/widgets/binding.dart]() 883:13                              drawFrame
packages[/flutter/src/rendering/binding.dart]() 363:5                             [_handlePersistentFrameCallback]
packages[/flutter/src/scheduler/binding.dart]() 1144:15                           [_invokeFrameCallback]
packages[/flutter/src/scheduler/binding.dart]() 1081:9                            handleDrawFrame
packages[/flutter/src/scheduler/binding.dart]() 995:5                             [_handleDrawFrame]
lib[/_engine/engine/platform_dispatcher.dart]() 1011:13                           invoke
lib[/_engine/engine/platform_dispatcher.dart]() 159:5                             invokeOnDrawFrame
lib[/_engine/engine/initialization.dart]() 128:45                                 <fn>
════════════════════════════════════════════════════════════════════════════════

I'm using the Modular package for dependency injection by the way

krokyze commented 2 years ago

Could you please try setting webRenderer to html as explained here https://github.com/iamSahdeep/seo_renderer#usage ?

felipesses commented 2 years ago

@krokyze setting the script as mentioned in the link and running flutter run --web-renderer html seems to work, thank you so much for your help!