flutter-code-editor
flutter-code-editor copied to clipboard
When I use TabBarView to include multiple CodeFields in children, he gets an error
Null check operator used on a null value
When the exception was thrown, this was the stack:
#0 _CodeFieldState.initState.
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?