Created
June 11, 2020 20:07
-
-
Save stargazing-dino/b0569102a23f82cddf9d175dbd265d15 to your computer and use it in GitHub Desktop.
_ZefyrLineState.bringIntoView error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:quill_delta/quill_delta.dart'; | |
import 'package:zefyr/zefyr.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
final pageController = PageController(initialPage: 0); | |
var pageTitles = [ | |
'page_1', | |
'page_2', | |
'page_3', | |
'page_4', | |
'page_5', | |
'page_6', | |
'page_7', | |
'page_8', | |
]; | |
var pageTexts = [ | |
'one\n', | |
'two\n', | |
'three\n', | |
'four\n', | |
'five\n', | |
'six\n', | |
'seven\n', | |
'eight\n', | |
]; | |
final kDuration = Duration(milliseconds: 250); | |
final kCurve = Curves.linear; | |
@override | |
Widget build(BuildContext context) { | |
final showError = true; | |
if (!showError) { | |
// For me, anything more than 6 elements throws | |
pageTitles = pageTitles.take(5); | |
pageTexts = pageTitles.take(5); | |
} | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
actions: [ | |
IconButton( | |
icon: Icon(Icons.arrow_back), | |
onPressed: () => pageController.animateToPage( | |
0, | |
duration: kDuration, | |
curve: kCurve, | |
), | |
), | |
IconButton( | |
icon: Icon(Icons.arrow_forward), | |
onPressed: () => pageController.animateToPage( | |
pageTitles.length, | |
duration: kDuration, | |
curve: kCurve, | |
), | |
) | |
], | |
), | |
body: SafeArea( | |
child: PageView.builder( | |
controller: pageController, | |
itemCount: pageTitles.length, | |
itemBuilder: (_, i) { | |
final title = pageTitles[i]; | |
final text = pageTexts[i]; | |
return Page(key: ValueKey(title), title: title, text: text); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} | |
class Page extends StatefulWidget { | |
Page({Key key, this.title, this.text}) : super(key: key); | |
final String title; | |
final String text; | |
@override | |
_PageState createState() => _PageState(); | |
} | |
class _PageState extends State<Page> { | |
ZefyrController textController; | |
final textFocusNode = FocusNode(); | |
@override | |
void dispose() { | |
textController.dispose(); | |
textFocusNode.dispose(); | |
super.dispose(); | |
} | |
@override | |
void initState() { | |
final Delta delta = Delta()..insert(widget.text); | |
textController = ZefyrController(NotusDocument.fromDelta(delta)); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return ZefyrScaffold( | |
child: Column( | |
children: [ | |
Text(widget.title), | |
ZefyrField( | |
height: 200.0, | |
controller: textController, | |
focusNode: textFocusNode, | |
) | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment