Skip to content

Commit

Permalink
fix: 'PageStorage.of' returns null (AppFlowy-IO#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Nov 6, 2023
1 parent 5c4f4ab commit aa90288
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
@override
void initState() {
super.initState();
ItemPosition? initialPosition = PageStorage.of(context).readState(context);
ItemPosition? initialPosition =
PageStorage.maybeOf(context)?.readState(context);
primary.target = initialPosition?.index ?? widget.initialScrollIndex;
primary.alignment =
initialPosition?.itemLeadingEdge ?? widget.initialAlignment;
Expand Down Expand Up @@ -670,7 +671,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
position.itemLeadingEdge < 1 && position.itemTrailingEdge > 0,
);
if (itemPositions.isNotEmpty) {
PageStorage.of(context).writeState(
PageStorage.maybeOf(context)?.writeState(
context,
itemPositions.reduce(
(value, element) =>
Expand Down
73 changes: 73 additions & 0 deletions test/customer/editor_on_overlay_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() async {
setUpAll(() {
TestWidgetsFlutterBinding.ensureInitialized();
});

testWidgets('customize highlight color', (tester) async {
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();

// tap the open editor button
final openEditorButton = find.byType(FloatingActionButton);
await tester.tap(openEditorButton);
await tester.pumpAndSettle();
});
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const Placeholder(),
floatingActionButton: FloatingActionButton(
onPressed: _insertEditorOnOverlay,
child: const Icon(Icons.add),
),
);
}

void _insertEditorOnOverlay() {
final overlayEntry = OverlayEntry(
builder: (_) {
return AppFlowyEditor(
editorState: EditorState.blank(),
);
},
);

Overlay.of(context).insert(overlayEntry);
}
}

0 comments on commit aa90288

Please sign in to comment.