简体   繁体   English

将 Flutter 的 MaterialApp 放入容器中

[英]Put Flutter's MaterialApp within Container

I want to display Flutter's MaterialApp in a centered container with a maximum width and height if it is viewed as a web app.如果将 Flutter 的 MaterialApp 视为 Web 应用程序,我想在具有最大宽度和高度的居中容器中显示它。 Intuitively, I thought it should work with something like the following, but that doesn't have any effect:直觉上,我认为它应该与以下内容一起使用,但这没有任何效果:

Container(
  constraints: BoxConstraints(maxHeight: 500, maxWidth: 500),
  child: MaterialApp( ... )
);
import 'package:flutter/material.dart';

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

class Launcher extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GenericScreen(), // or any screen using routes param
      builder: (context, child) => child!,
    );
  }
}

class GenericScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FractionallySizedBox(
      widthFactor: .8,
      child: Scaffold(appBar: AppBar()),
    );
  }
}

There is a pub called Flutter Web Frame:有一个酒吧叫 Flutter Web Frame:

Make the frame max width / size when on large devices such as Web or Desktop.在大型设备(如 Web 或桌面)上设置框架的最大宽度/大小。

This is very suitable to be used to limit the size of content, if your application is not yet available a responsive version if it is run on multiple devices / platforms.这非常适合用于限制内容的大小,如果您的应用程序在多个设备/平台上运行时还没有响应版本。

https://pub.dev/packages/flutter_web_frame https://pub.dev/packages/flutter_web_frame

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM