你怎么会FlatButton成为一个圆形边框的按钮?我使用圆形边框形状,RoundedRectangleBorder但不知何故需要为边框着色.
new FlatButton(
  child: new Text("Button text),
  onPressed: null,
  shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)
Run Code Online (Sandbox Code Playgroud)
 我的应用程序中有两个屏幕。
屏幕 A 在打开时运行计算成本很高的操作,并通过在dispose()调用时取消动画/订阅数据库来正确处理以防止内存泄漏。
从屏幕 A,您可以打开另一个屏幕(屏幕 B)。
当我使用 时Navigator.pushNamed,屏幕 A 保留在内存中,dispose()不会被调用,即使现在显示了屏幕 B。
有没有办法在屏幕 A 不在视野中时强制处理它?
永远不会处理第一条路线的示例代码:
import 'package:flutter/material.dart';
void main() {
  runApp(MaterialApp(
    title: 'Navigation Basics',
    home: FirstRoute(),
  ));
}
class FirstRoute extends StatefulWidget {
  @override
  _FirstRouteState createState() => _FirstRouteState();
}
class _FirstRouteState extends State<FirstRoute> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: RaisedButton(
        child: Text('Open route'),
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => SecondRoute()),
          );
        }, …Run Code Online (Sandbox Code Playgroud) 从这个问题,我使用 Flutter 的 SVG 包 ( flutter_svg) 来渲染SVG 图像。
我想使用 SVG 作为中间的Container背景Text。
这是我到目前为止的代码:
Container(
      decoration: BoxDecoration(
          image: DecorationImage(image: SvgPicture.asset(
            'assets/example.svg',
          ),),
      ),
      children: <Widget>[
        Text('Welcome to my Flutter App',
          style: Theme.of(context).textTheme.display1.copyWith(
            color: Colors.white,
            fontWeight: FontWeight.bold
          )
        ),
      ],
    )
Run Code Online (Sandbox Code Playgroud)
我发现的问题是这SvgPicture不是一个,ImageProvider所以我无法添加BoxDecoration来获取背景图像。
有没有办法然后SvgPicture用作容器的盒子装饰或背景?
在我的小部件代码中,我需要在 Android/iOS 上进行分支,以显示特定于每个平台的小部件,并调用特定于平台的 API(例如,Android 小部件将调用仅在 Android 上可用的 API)。
  if (Platform.isAndroid) {
    return WidgetAndroid(...);
  } else if (Platform.isIOS) {
    return WidgetIOS(...);
  }
Run Code Online (Sandbox Code Playgroud)
如何使用 Flutter 小部件测试来测试是否显示正确的小部件?
我知道我可以检查该小部件是否存在,但如何在特定平台上运行测试。
expect(find.byType(WidgetIOS), findsOneWidget);
Run Code Online (Sandbox Code Playgroud) 有没有办法在使用时更改叠加背景颜色showModalBottomSheet?
现在颜色总是灰色,但我想使用不同的颜色,如绿色,如下所示。
这是演示中使用的代码以供参考
        showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
          return Container(
            child: Padding(
              padding: const EdgeInsets.all(32.0),
              child: Text('This is the modal bottom sheet. Tap anywhere to dismiss.',
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: Theme.of(context).accentColor,
                  fontSize: 24.0
                )
              )
            )
          );
        });
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个简单的测试用例应用程序,您单击一个小部件,使用GestureDetector该小部件触发setState对tapCount变量的更新.
应用程序在模拟器中正常工作,如上所示正确更新文本,但是一旦我尝试Flutter小部件测试,小部件测试就会失败,因为文本在测试环境中没有正确更新.
可重复的例子:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
  MyApp();
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
  int tapCount = 0;
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Column(
            children: <Widget>[
              MyImage(
                onTap: () {
                  setState(() {
                    tapCount += 1;
                  });
                },
                imagePath: 'assets/my-image.jpg',
              ),
              Text(tapCount.toString())
            ],
          ),
        ),
      ),
    );
  }
}
class MyImage extends StatelessWidget {
  final Function() onTap; …Run Code Online (Sandbox Code Playgroud) 我有RichText一些TextSpan.我希望其中一个TextSpan小部件有一个背景,所以我用background: Paint()..color = Colors.redAccent它的文本样式.
有没有办法在背景中添加一些额外的红色空间/填充.
这是它目前的样子:
这就是我想要它的样子(注意突出显示文本顶部和底部的额外红色):
这是使用的代码:
Scaffold(
  appBar: new AppBar(),
  body: new RichText(
    text: new TextSpan(
      text: 'This is a one the lines in the span \n ',
      style: TextStyle(fontSize: 15.0, color: Colors.black),
      children: <TextSpan>[
        new TextSpan(
            text: 'This is the second line',
            style: new TextStyle(fontWeight: FontWeight.bold)),
        new TextSpan(
            text: ' background on me ',
            style: new TextStyle(
              fontWeight: FontWeight.bold,
              background: Paint()..color = Colors.redAccent,
            )),
        new TextSpan(text: ' This is …Run Code Online (Sandbox Code Playgroud) 我MaterialApp在 Flutter 中有一个,并且希望fontFamily在ThemeData.
这是因为这某些fontFamily看起来比其他字体小。
有没有办法使用 放大整个应用程序的字体大小ThemeData?
如果我们有一个小部件TextSpan的子代,RichText您将如何测试文本内容.
new TextSpan(
  text: 'Hello world!',
  style: new TextStyle(color: Colors.black),
)
Run Code Online (Sandbox Code Playgroud)
在您的测试中,使用Text小部件,您可以使用expect(find.text('Hello world!'), findsOneWidget),但如果您有一个小部件,则不起作用TextSpan.
expect(find.byType(TextSpan), findsOneWidget)也找不到任何类型的小部件TextSpan.
在创建ListView(来自文档的示例)时,我们如何更改使用带有 Flutter 的 iOS 模拟器滚动时出现在列表顶部的反弹颜色?
ListView(
  children: <Widget>[
    ListTile(
      leading: Icon(Icons.map),
      title: Text('Map'),
    ),
    ListTile(
      leading: Icon(Icons.photo_album),
      title: Text('Album'),
    ),
    ListTile(
      leading: Icon(Icons.phone),
      title: Text('Phone'),
    ),
  ],
);
Run Code Online (Sandbox Code Playgroud)
按照这个问题,在没有 Flutter 的 iOS 开发中,你会做这样的事情来定位屏幕外的视图以更改反弹颜色:
override func viewDidLoad() {
    super.viewDidLoad()
    let topView = UIView(frame: CGRect(x: 0, y: -collectionView!.bounds.height,
        width: collectionView!.bounds.width, height: collectionView!.bounds.height))
    topView.backgroundColor = .blackColor()
    collectionView!.addSubview(topView)
}
Run Code Online (Sandbox Code Playgroud)
Flutter 是否有等价物?