我无法修复这个错误
RenderBox 未布局:RenderPointerListener#2b92a relayoutBoundary=up9 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart':断言失败:第 1940 行 pos 12:'hasSize'。相关的导致错误的小部件是 ->ListView
这是我的所有产品部分。
import 'package:flutter/material.dart';
import 'package:hospital/Drawer/drawercontent.dart';
import 'package:hospital/Product/AllProducts/ProductList/product_list.dart';
import 'package:hospital/Product/AllProducts/carousel.dart';
import 'package:hospital/Product/AllProducts/category.dart';
class AllProducts extends StatefulWidget {
@override
_AllProductsState createState() => _AllProductsState();
}
class _AllProductsState extends State<AllProducts> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
title: Text(
"Product",
style: TextStyle(fontStyle: FontStyle.italic),
),
actions: [
IconButton(
icon: Icon(Icons.person),
onPressed: () => print("open cart"),
),
],
),
drawer: Drawer(
child: DrawerContent(),
),
body: ListView(
children: [
Carousel(), …Run Code Online (Sandbox Code Playgroud) flutter flutter-test flutter-dependencies flutter-layout flutter-animation
我收到“可为空表达式”错误。问题出现在以下几行中:
left: isSideBarOpenedAsync.data ? 0 : 0,
right: isSideBarOpenedAsync.data ? 0 : screenWidth - 35,
Run Code Online (Sandbox Code Playgroud)
isSideBarOpenedAsync类型在哪里AsyncSnapshot<bool>
这是我收到的错误
可为空的表达式不能用作条件。
null在将其用作条件之前,请尝试检查该值是否存在。
这是完整的代码供参考
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:solaris/constants.dart';
import 'package:rxdart/rxdart.dart';
class SideBar extends StatefulWidget {
@override
_SideBarState createState() => _SideBarState();
}
class _SideBarState extends State<SideBar> with SingleTickerProviderStateMixin<SideBar>{
late AnimationController _animationController;
late StreamController<bool> isSidebarOpenedStreamController;
late Stream<bool> isSideBarOpenedStream;
late StreamSink<bool> isSideBarOpenedSink;
final _animationDuration = const Duration(milliseconds: 500);
@override
void initState(){
super.initState();
_animationController = AnimationController(vsync: this, duration: _animationDuration);
isSidebarOpenedStreamController = PublishSubject<bool>();
isSideBarOpenedStream …Run Code Online (Sandbox Code Playgroud) 我正在尝试在颤振中显示 gif。
我正在使用代码
Image(image : NetworkImage(message.image_url))
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
Another exception was thrown: Exception: HTTP request failed, statusCode: 403, https://media.giphy.com/media/13AXYJh2jDt2IE/giphy.gif%20
Run Code Online (Sandbox Code Playgroud) 当我使用 时Navigator.pushNamed(context, "/someRoute");,有一个最小动画从屏幕底部滑入新路线(在 Android 上,在 iOS 上可能看起来不同)。
如何向此过渡添加自定义动画?
我找到了这篇文章,其中有一些非常简洁的未命名路由示例代码。他们实现自己的类继承自PageRouteBuilder并可以这样使用:Navigator.push(context, SlideRightRoute(page: Screen2()))。但是 aPageRouteBuilder不是 Widget 并且不能在MaterialApp. 所以我不知道如何将它应用于命名路由。
在 flutter 1.22 更新后,我在 Lineargradient 颜色属性中收到一个错误,它给我一个错误,即名称颜色参数未定义..在 android 中的 flutter 和 flutter 插件更新后,我在项目中的任何地方都收到此错误工作室。
dart flutter flutter-dependencies flutter-layout flutter-animation
我想创建一个水平滚动列表,当从左侧或右侧滑动时,使用捕捉以适应效果.
每张卡片之间有一些间距,适合屏幕,类似于下图
除此之外,这些可水平滚动的列表元素应包含在垂直可滚动列表中.
我所能实现的只是在flutter docs中跟随示例之后才显示水平滚动卡列表.
class SnapCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
],
),
),
),
);
} …Run Code Online (Sandbox Code Playgroud) dart flutter flutter-sliver flutter-layout flutter-animation
我有一个 FlutterText小部件,它的内容是从外部 REST 调用填充的。我想通过调用 REST 端点每 5 分钟定期刷新小部件内容。
到目前为止,我设法每 5 分钟调用一次端点,但无法使用来自网络的新数据更新/刷新小部件内容。
class PatientCount {
int count;
double amount;
PatientCount({this.count, this.amount});
PatientCount.fromJson(Map<String, dynamic> map)
: count = map['count'],
amount = map['amount'];
}
Future<PatientCount> fetchPatientCount() async {
var url = "http://localhost:9092/hms/patients-count-on-day";
Map<String, String> requestHeaders = new Map<String, String>();
requestHeaders["Accept"] = "application/json";
requestHeaders["Content-type"] = "application/json";
String requestBody = '{"consultedOn":' + '16112018' + '}';
http.Response response =
await http.post(url, headers: requestHeaders, body: requestBody);
final statusCode = response.statusCode;
final Map responseBody = json.decode(response.body); …Run Code Online (Sandbox Code Playgroud) 我有两个垂直列表,一个在左侧,另一个在右侧,我们称它们为“选定列表”和“未选定列表”。我希望未选定列表中的项目从屏幕左侧动画到右侧并添加到选定列表中。其他项目应填充未选定列表中的空白空间,而选定列表中的项目应为新项目释放空间。 这是用户界面
我的代码:
class AddToFave extends StatefulWidget {
const AddToFave({Key? key}) : super(key: key);
@override
_AddToFaveState createState() => _AddToFaveState();
}
class _AddToFaveState extends State<AddToFave> {
List<String> unselected = [ '1','2','3','4','5','6','7','8','9','10'];
List<String> selected = [];
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width / 5,
height: MediaQuery.of(context).size.height,
child: ListView.builder(
itemCount: selected.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
unselected.add(selected[index]);
selected.removeAt(index);
setState(() {});
},
child: Container(
width: MediaQuery.of(context).size.width / 5, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Flutter中的圆角创建一个警告对话框,如下面的屏幕截图所示.也在这里添加我的代码,但我的输出与预期的完全不同.有人,请帮帮我.

我的代码在这里.
void _showAlert() {
AlertDialog dialog = new AlertDialog(
content: new Container(
width: 260.0,
height: 230.0,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
color: const Color(0xFFFFFF),
borderRadius: new BorderRadius.all(new Radius.circular(32.0)),
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// dialog top
new Expanded(
child: new Row(
children: <Widget>[
new Container(
// padding: new EdgeInsets.all(10.0),
decoration: new BoxDecoration(
color: Colors.white,
),
child: new Text(
'Rate',
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
fontFamily: 'helvetica_neue_light',
),
textAlign: TextAlign.center,
),
),
],
),
), …Run Code Online (Sandbox Code Playgroud) Discrete with Custom Theme 我尝试改变拇指形状。但我想将拇指更改为图像。
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/material.dart';
class SliderDemo extends StatefulWidget {
static const String routeName = '/material/slider';
@override
_SliderDemoState createState() => new _SliderDemoState();
}
Path _triangle(double size, Offset thumbCenter, {bool invert = false}) {
final Path thumbPath = new Path();
final double height = …Run Code Online (Sandbox Code Playgroud)