小编Mah*_*ahi的帖子

对空值使用空检查运算符 - Flutter

我试图制作一个谷歌驱动器应用程序,列出驱动器中的文件。但我在空值错误上使用了空检查运算符。我知道发生了什么事。但我无法解决它。

 @override
  Widget build(BuildContext context) {
    return Scaffold(
         body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextButton(
              onPressed: () {},
              child: Text('UPLOAD'),
            ),
            if (list != null)
              SizedBox(
                height: 300,
                width: double.infinity,
                child: ListView.builder(
                  shrinkWrap: true,
                  itemCount: list!.files?.length,
                  itemBuilder: (context, index) {
                    final title = list!.files![index].originalFilename;
                    return ListTile(
                      leading: Text(title!),
                      trailing: ElevatedButton(
                        child: Text('Download'),
                        onPressed: () {
                        },
                      ),
                    );
                  },
                ),
              )
          ],
        ),
      ),
      floatingActionButton: Row(
        children: [
          FloatingActionButton(
            onPressed: _listGoogleDriveFiles,
            child: Icon(Icons.photo),
          ),
          FloatingActionButton(
            onPressed: _incrementCounter,
            tooltip: …
Run Code Online (Sandbox Code Playgroud)

dart google-drive-api flutter dart-null-safety

4
推荐指数
1
解决办法
3万
查看次数

如何使用 SingleChildScrollView 滚动到 Flutter 中的特定小部件

我有一个主屏幕和第二屏幕。当主屏幕中的抽屉项目单击时。它应该移动到 SecondScreen Container 小部件。但如何做到这一点呢?

我已经为 SecondScreen SingleChildScrollView 设置了 ScrollController 。但如何移动到某个小部件呢?

  1. 在 SecondScreen 中创建一个滚动到小部件的方法?
  2. 如果我有第三个屏幕需要相同的功能怎么办?

SecondScreen.dart

import 'package:flutter/material.dart';
  ScrollController scrollController = ScrollController();
  var containerKey = GlobalKey();
class SecondScreen extends StatefulWidget {

  final Key widgetKey;

  const SecondScreen({Key key, this.widgetKey}) : super(key: key);

  @override
  State<SecondScreen> createState() => _SecondScreenState();
}

class _SecondScreenState extends State<SecondScreen> {

@override
  void initState() {
    // TODO: implement initState
    super.initState();
Scrollable.ensureVisible(
    widget.widgetKey,
    duration: const Duration(milliseconds: 400),
    curve: Curves.easeInOut,
);
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        controller: …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout flutter-animation

3
推荐指数
1
解决办法
4910
查看次数

'RenderObject?' 类型的值 不能分配给类型为“RenderRepaintBoundary”的变量

这可能是一个简单的问题,但我找不到答案。当我使用此代码时:

RenderRepaintBoundary boundary =
                key.currentContext.findRenderObject();
Run Code Online (Sandbox Code Playgroud)

我有错误:

'RenderObject?' 类型的值 不能分配给“RenderRepaintBoundary”类型的变量。?

很好,当我使用 dart version: 时2.7.0,当我将其更改为时会出现问题2.12.0

dart flutter

0
推荐指数
2
解决办法
379
查看次数

如何在flutter中制作透明的底部导航栏

应用程序屏幕上覆盖着图像,有一个底部应用程序栏,我需要将背景图像视为透明。

我使用 svg 图标作为底部导航栏图标。同一屏幕顶部应用栏是透明的,但底部应用栏显示白色。



  BottomAppBar _buildBottomNavigationBar() {
    return BottomAppBar(
      color: Colors.transparent,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          IconButton(
            onPressed: () {},
            icon: SvgPicture.asset(
              'assets/icons/home.svg',
              color: Colors.black,
            ),
            //color: Colors.black,
          ),
          IconButton(
            onPressed: () {},
            icon: SvgPicture.asset('assets/icons/location.svg'),
            color: Colors.black,
          ),
          IconButton(
            onPressed: () {},
            icon: SvgPicture.asset('assets/icons/fish.svg'),
            color: Colors.black,
          ),
          IconButton(
            onPressed: () {},
            icon: SvgPicture.asset('assets/icons/menu.svg'),
            color: Colors.black,
          ),
        ],
      ),
    );
  }

Run Code Online (Sandbox Code Playgroud)

transparent dart flutter bottomnavigationview

0
推荐指数
1
解决办法
1929
查看次数