flutter-elementary
flutter-elementary copied to clipboard
Passing wm inside child widgets?
I have ElementaryWidget that contains Scaffold inside it and I decided to spread Scaffold into AppBar, Body and Bottom classes like this:
< some other imports … >
part 'widgets/chat_page_app_bar.dart';
part 'widgets/chat_page_body.dart';
part 'widgets/chat_page_bottom_bar.dart';
class ChatPageWidget extends ElementaryWidget<IChatPageWidgetModel> {
final String title;
const ChatPageWidget({
Key? key,
this.title = 'Чат с диспетчером',
WidgetModelFactory wmFactory = defaultChatPageWidgetModelFactory,
}) : super(wmFactory, key: key);
@override
Widget build(IChatPageWidgetModel wm) {
return GestureDetector(
onTap: wm.onTapOutsideMessageTextField,
child: Scaffold(
resizeToAvoidBottomInset: true,
appBar: ChatPageAppBar(title: title),
body: Column(
children: [
Expanded(
child: ChatPageBody(
wmFactory,
)),
ChatPageBottomBar(wmFactory)
],
),
));
}
}
These parts extends Elementary Widget<IChat Page Widget Model> as well. Of course, I faced with issue when new Widget Model instance creates each time instead of using the same instance created in parent ChatPageWidget. I could convert parts to simple Stateless widgets and pass wm variable in their constructors but in this case I have access to context leaks to its build method that breaking single source of truth of WidgetModel.
Is there way to keep AppBar, Body and BottomBar widgets as ElementaryWidgets with build(IChatPageWidgetModel wm) function instead of build(BuildContext context) one?