如果没有脚手架,Material App样式将无法正常工作 [英] Material App styles doesn't work without Scaffold

查看:52
本文介绍了如果没有脚手架,Material App样式将无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个没有Scaffold元素的Material design应用:这是纯粹的默认应用:

I'm trying to create a Material design app without the Scaffold element: Here is the purely default app:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Text(widget.title);
  }
}

结果是:

如何在不使用脚手架的情况下解决该问题并使用材质样式?

How to fix that and use material styles without Scaffold?

答案:

我需要使用 Material 小部件.作为Flutter的初学者,我已经阅读了Material Design设计教程,并且所有教程都使用了 Scaffold 小部件.感谢您在注释中指出 Material 小部件.

I need to use the Material widget. As a very beginner in Flutter I had read Material design tutorials and all of them were using the Scaffold widget. Thanks for pointing out the Material widget in comments.

推荐答案

没有脚手架将无法正常工作.

It will not work without scaffold.

我认为您没有得到什么是支架及其行为?

I think you are not getting what scaffold is and how it's behaviour is?

脚手架是一个小部件,可为您的屏幕/路由提供类似于Android/ios屏幕的默认行为,例如AppBar,Body,Title,FloatingActionButton,Drawer等.

Scaffold is a widget which provides your screen/route a default behaviour similar to your android/ios screens like AppBar, Body, Title, FloatingActionButton, Drawer etc.

这样您就不必使自己成为新的结构.

So that you do not have to make yourself a new structure.

如果您不使用脚手架,那么您的页面将像普通的主体结构一样,您必须在其中按需填充自定义小部件.

If you are not using scaffold, then your page will act like a plain body structure in which you have to fill custom widgets as per your requirements.

例如:

在android中,任何活动"将具有默认的ActionBar.但是,如果您使用NoActionBarActivity,那么活动将显示而没有actionBar.

In android, Any Activity will have a default ActionBar. But, if you use NoActionBarActivity then Activity will be displayed without actionBar.

即使脚手架也以类似的方式工作.

Even Scaffold works in the similar manner.

更新的方法:

@override
  Widget build(BuildContext context) {
    return Material(child: Center(child: Text(widget.title,)),color: Colors.white,);
  }

您需要使用 Material Widget (材质小部件)作为父级,以便在使用脚手架时以类似方式处理子级小部件.

You need to use Material Widget as a parent to behave the child widgets in the similar manner when using Scaffold.

这篇关于如果没有脚手架,Material App样式将无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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