在设计支持库(来自I/O)中,Google推出了AppBarLayout.当用户在片段中的WebView中滚动网站时,我正在尝试使工具栏动画出屏幕.当我将我的WebView元素放在NestedScrollView中时它确实有效,但这会使滚动浏览WebView错误并使得缩放变得不可能.如何让AppBarLayout响应(向下滚动时动画,在向上滚动时返回,就像在NestedScrollView中一样)到WebView?这些是我的XML文件:主要布局:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/main_coordinatorlayout">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/appBarLayout">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/Theme.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabLayout"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/viewPager"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="0dp"
android:layout_margin="16dp"
android:src="@drawable/ic_action_autorenew" />
Run Code Online (Sandbox Code Playgroud)
包含webview的片段代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
android:layout_gravity="center_horizontal"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)
提前致谢!
在我正在构建的Flutter应用程序中,我需要根据自定义(非Google/Facebook/Twitter/etc)授权服务器对用户进行身份验证.
为了实现这一点,用户应在网页中填写凭据.为此,可以使用WebView插件.但是,在用户进行身份验证后重定向页面时,应关闭WebView,并将代码传递给最初调用WebView的(Flutter)函数.
我已经做了一些研究,我得到了以下几个选项:
是否存在解决方案,一旦打开redirect-URI,它会自动关闭浏览器(并返回验证码)?
提前致谢!
我正在尝试使用.of()方法获取我的应用程序的顶级状态,类似于Scaffold.of()函数.这是(精简的)代码:
class IApp extends StatefulWidget {
@override
IAppState createState() => new IAppState();
static IAppState of(BuildContext context) =>
context.ancestorStateOfType(const TypeMatcher<IAppState>());
}
Run Code Online (Sandbox Code Playgroud)
该应用程序使用runApp(新IApp)启动
此窗口小部件创建一个HomePage:
@override
Widget build(BuildContext context) {
return new MaterialApp(
// ommitted: some localization and theming details
home: new HomePage(),
);
}
Run Code Online (Sandbox Code Playgroud)
然后,我尝试从HomePage(StatefulWidget本身)访问状态:
@override
Widget build(BuildContext context) {
return new Scaffold(
// ommited: some Scaffold properties such as AppBar
// runtimeType not actual goal, but just for demonstration purposes
body: new Text(IApp.of(context).runtimeType.toString()),
);
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我将HomePage的代码放在与 IApp 相同的文件中时,代码可以工作,但只是作为一个额外的类.但是,当我将HomePage 放在一个单独的文件 …