如何在不带脚手架的Flutter中使用抽屉? [英] How to use drawer in Flutter without Scaffold?

查看:69
本文介绍了如何在不带脚手架的Flutter中使用抽屉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flutter内置了Material Design内置的一整套组件.当Scaffold为许多开发人员简化事情时,我的案例就是一个奇怪的案例,我想要在透明appbar后面放置主体.

Flutter has a whole class of components from Material Design built-in. When the Scaffold makes things easier for a lot of developers, my case is a weird one where I want the body behind the transparent appbar.

如何显示脚手架小部件的Appbar下方的主体,而不是波纹管?

我切换为使用Stack来设置应用栏和正文中的其他内容.现在,我觉得使用材料设计库中的大多数组件变得更加困难.大多数事情都变得越来越困难,因为它到处都是与Scaffold组件链接的,而我没有使用它.

I switched to use Stack for setting up the appbar and other content in the body. Now I feel it is harder to use most components from the material design library. Most things get harder as everywhere it gets linked to Scaffold component and I'm not using it.

如何在不使用脚手架的情况下在Flutter中实现抽屉?

How should I implement a drawer in Flutter without using Scaffold?

推荐答案

我将在此处给出一个答案.

I'm going to give a sort-of-answer here.

绝对有可能只使用ScaffoldController和MultiChildLayoutDelegate来实现与Scaffold相同的方式(关于flutter的好处是,所有内容都是开源的,因此您可以阅读和复制相关部分),但是不简单.如果您确实想这样做,建议您阅读脚手架的源代码,直到您了解发生了什么.然后,您可以复制代码的相关部分,直到代码起作用为止.

It is definitely possible to do using just a ScaffoldController and a MultiChildLayoutDelegate in the same way that Scaffold does it (this nice thing about flutter is that everything is open source so you can read & duplicate the relevant parts), but it is not simple. If you really want to do this, I'd advise reading through the source code for Scaffold until you understand what's going on. You could then copy out the relevant parts of code until you have it working.

尽管我认为这对您有用,但是有一种更简单的方法.我建议您使用脚手架.没什么好说的,您必须使用它的 AppBar -您仍然可以将自定义实现包含在主体中.这样,您无需执行&即可获得 drawer ,包括LTR RTL内容以及Scaffold所做的任何其他事情.维护所有这些.

There is an easier way though that I think would work for you. I would recommend instead that you do use a scaffold. There's nothing saying you have to use its AppBar - you can still have your custom implementation contained within the body. This way, you get drawer, including LTR RTL stuff and whatever else Scaffold does, without having to implement & maintain all of it.

如果这仍然对您不起作用,并且您无法从任何地方浏览源代码,请告诉我,如果我有更多时间,我也许可以考虑创建一个简单的示例.

If this still doesn't work for you and you can't get anywhere looking through the source, let me know and I might be able to look into creating a simple example when I have more time.

这篇关于如何在不带脚手架的Flutter中使用抽屉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆