flutter-code-editor icon indicating copy to clipboard operation
flutter-code-editor copied to clipboard

When I use TabBarView to include multiple CodeFields in children, he gets an error

Open peter100u opened this issue 2 years ago • 1 comments

Null check operator used on a null value

When the exception was thrown, this was the stack: #0 _CodeFieldState.initState. (package:flutter_code_editor/src/code_field/code_field.dart:208:56) #1 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1286:15) #2 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1225:9) #3 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1074:5) #4 _invoke (dart:ui/hooks.dart:142:13) #5 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5) #6 _drawFrame (dart:ui/hooks.dart:112:31)

peter100u avatar Feb 03 '23 11:02 peter100u

Unfortunately I wasn't able to reproduce the issue.

I tried using the following code:

import 'package:flutter/material.dart';
import 'package:flutter_code_editor/flutter_code_editor.dart';
import 'package:highlight/languages/dart.dart';
import 'package:highlight/languages/java.dart';

import '../common/snippets.dart';
import '../common/themes.dart';

const _defaultTheme = 'monokai-sublime';

void main(List<String> args) {
runApp(const MyTabBarCodeField());
}

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

@override
State<MyTabBarCodeField> createState() => _MyTabBarCodeFieldState();
}

class _MyTabBarCodeFieldState extends State<MyTabBarCodeField> {
final _theme = _defaultTheme;
final dartController = CodeController(language: dart, text: dartSnippet);
final javaController =
    CodeController(language: java, text: javaFactorialSnippet);

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          bottom: const TabBar(
            tabs: [
              Icon(Icons.coffee),
              FlutterLogo(),
            ],
          ),
        ),
        body: TabBarView(
          children: [
            ListView(
              children: [
                CodeTheme(
                  data: CodeThemeData(styles: themes[_theme]),
                  child: CodeField(
                    focusNode: FocusNode(),
                    controller: javaController,
                    textStyle: const TextStyle(fontFamily: 'SourceCode'),
                    gutterStyle: const GutterStyle(
                      textStyle: TextStyle(
                        color: Colors.purple,
                      ),
                    ),
                  ),
                ),
              ],
            ),
            ListView(
              children: [
                CodeTheme(
                  data: CodeThemeData(styles: themes[_theme]),
                  child: CodeField(
                    focusNode: FocusNode(),
                    controller: dartController,
                    textStyle: const TextStyle(fontFamily: 'SourceCode'),
                    gutterStyle: const GutterStyle(
                      textStyle: TextStyle(
                        color: Colors.purple,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    ),
  );
}
}

If you still have this issue can you please provide steps to reproduce the issue or the code?

yescorp avatar Feb 16 '23 17:02 yescorp