如何修复window 选项卡最小化WEB 时右溢出的问题?

how to fix right overflowed when window tab is minimized WEB flutter?

我正在尝试在 FLUTTER WEB 中创建自定义应用栏,但我遇到了这个问题, 当包含我的应用程序 UI 的 chrome 的 windows 最小化时,容器内部的内容从右侧重叠 x 像素。 container contains Flexible widget, Flexible 有 Row widget child, Row children 包含类型 Inkwell.

我尝试过的解决方案:

  1. 灵活的小部件。
  2. 包装小部件。
  3. TextOverFlow 省略号和 褪色。

这是我的代码:

custom_app_bar.dart

class CustomAppBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(20),
      padding: EdgeInsets.all(20),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(46),
        boxShadow: [
          BoxShadow(
            offset: Offset(0, -2),
            blurRadius: 30,
            color: Colors.black.withOpacity(0.16),
          ),
        ],
      ),
      child: Flexible(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Expanded(
              child: Text(
                "someText".toUpperCase(),
                style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Spacer(),
            MenuItem1(
              title: "someText",
              press: () {},
              overflow: TextOverflow.ellipsis,
            ),
            MenuItem1(
              title: "someText",
              press: () {},
              overflow: TextOverflow.ellipsis,
            ),

            MenuItem1(
              title: "someText",
              press: () {},
              overflow: TextOverflow.ellipsis,
            ),

            MenuItem1(
              title: "someText",
              press: () {},
              overflow: TextOverflow.ellipsis,
            ),
          ],
        ),
      ),
    );
  }
}

menu_item.dart

class MenuItem1 extends StatelessWidget {
  final String title;
  final TextOverflow overflow;
  final VoidCallback press;
  const MenuItem1(
      {Key? key,
      required this.title,
      required this.press,
      required this.overflow})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: press,
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: 50,
        ),
        child: Text(
          title.toUpperCase(),
          overflow: overflow,
          style: TextStyle(
            color: kTextcolor.withOpacity(0.3),
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );
  }
}

您必须指定小部件需要多少宽度才能溢出。

这可能不是您想要的,但可能会有所帮助。

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          CustomAppBar(),
        ],
      ),
    );
  }
}

class CustomAppBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.all(20),
      padding: EdgeInsets.all(20),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(46),
        boxShadow: [
          BoxShadow(
            offset: Offset(0, -2),
            blurRadius: 30,
            color: Colors.black.withOpacity(0.16),
          ),
        ],
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Expanded(
            child: Text(
              "someText".toUpperCase(),
              style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
              overflow: TextOverflow.ellipsis,
            ),
          ),
        
          MenuItem1(
            title: "someText",
            press: () {},
            overflow: TextOverflow.ellipsis,
          ),
          MenuItem1(
            title: "someText",
            press: () {},
            overflow: TextOverflow.ellipsis,
          ),
          MenuItem1(
            title: "someText",
            press: () {},
            overflow: TextOverflow.ellipsis,
          ),
          MenuItem1(
            title: "someText",
            press: () {},
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    );
  }
}

class MenuItem1 extends StatelessWidget {
  final String title;
  final TextOverflow overflow;
  final VoidCallback press;
  const MenuItem1(
      {Key? key,
      required this.title,
      required this.press,
      required this.overflow})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: InkWell(
        onTap: press,
        child: Padding(
          padding: const EdgeInsets.symmetric(
            horizontal: 50,
          ),
          child: Text(
            title.toUpperCase(),
            overflow: overflow,
            style: TextStyle(
              color: Colors.black.withOpacity(0.3),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
      ),
    );
  }
}

你可以在 dartpad 中运行这个。