remove store from being a property. also better animation

This commit is contained in:
Filip Krawczyk 2022-08-25 18:22:14 +02:00
parent e3b561835b
commit b2ef0883e3
1 changed files with 34 additions and 23 deletions

View File

@ -42,26 +42,36 @@ enum HeaderLevel {
class EditorToolbar extends HookWidget {
final TextEditingController controller;
final String instanceHost;
final EditorToolbarStore store;
final FocusNode editorFocusNode;
static const _height = 50.0;
EditorToolbar({
const EditorToolbar({
required this.controller,
required this.instanceHost,
required this.editorFocusNode,
}) : store = EditorToolbarStore(instanceHost);
});
@override
Widget build(BuildContext context) {
final visible = useListenable(editorFocusNode).hasFocus;
return MobxProvider(
create: (context) => store,
child: AsyncStoreListener(
create: (context) => EditorToolbarStore(instanceHost),
child: ObserverBuilder<EditorToolbarStore>(builder: (context, store) {
return AsyncStoreListener(
asyncStore: store.imageUploadState,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
duration: kThemeAnimationDuration,
transitionBuilder: (child, animation) {
final offsetAnimation =
Tween<Offset>(begin: const Offset(0, 1.5), end: Offset.zero)
.animate(animation);
return SlideTransition(
position: offsetAnimation,
child: child,
);
},
child: visible
? Container(
height: _height,
@ -77,7 +87,8 @@ class EditorToolbar extends HookWidget {
)
: const SizedBox.shrink(),
),
),
);
}),
);
}