我试图制作一个谷歌驱动器应用程序,列出驱动器中的文件。但我在空值错误上使用了空检查运算符。我知道发生了什么事。但我无法解决它。
@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) 我有一个主屏幕和第二屏幕。当主屏幕中的抽屉项目单击时。它应该移动到 SecondScreen Container 小部件。但如何做到这一点呢?
我已经为 SecondScreen SingleChildScrollView 设置了 ScrollController 。但如何移动到某个小部件呢?
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) 这可能是一个简单的问题,但我找不到答案。当我使用此代码时:
RenderRepaintBoundary boundary =
key.currentContext.findRenderObject();
Run Code Online (Sandbox Code Playgroud)
我有错误:
'RenderObject?' 类型的值 不能分配给“RenderRepaintBoundary”类型的变量。?
很好,当我使用 dart version: 时2.7.0
,当我将其更改为时会出现问题2.12.0
应用程序屏幕上覆盖着图像,有一个底部应用程序栏,我需要将背景图像视为透明。
我使用 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)