我想将图像设置为脚手架的背景色。设置AppBar和底部栏时,使用Container的装饰作为支架的主体不会覆盖整个屏幕。
我想显示全屏背景。以下是我的脚手架代码:
Scaffold(
backgroundColor: Image.asset('images/background.png').color,
body: Container(
decoration: defaultAppBoxDecoration(),
),
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
title: Text('Title here', style: TextStyle(color: Colors.teal),),
leading: IconButton(
icon: Image.asset('images/star.png'),
onPressed: () {},
),
actions: <Widget>[
IconButton(icon: Image.asset('images/star.png')),
// IconButton(icon: Image.asset('images/grid.png')),
],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: IconButton(icon: Image.asset('images/star.png')),
),
bottomNavigationBar: Container(
padding: EdgeInsets.only(left: 4.0, right: 4.0),
height: 44.0 + MediaQuery.of(context).padding.bottom,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(icon: Image.asset('images/star.png')),
IconButton(icon: Image.asset('images/star.png')),
],
),
),
);
Run Code Online (Sandbox Code Playgroud)
需要了解什么时候应该Bloc模式以及Bloc的生命周期(如何释放持有内存的对象)
我有一个屏幕,我从服务器获取数据,数据将仅用于单个屏幕。我正在使用 Bloc 模式来显示数据。
使用 Bloc 模式时,我有一个正在使用 StatelessWidget 的屏幕。我正在尝试处理“WillPopScope”上的流。一旦被处置,流就不能再使用。因为访问同一屏幕会导致崩溃,因为我用 Bloc 包装了 MaterialApp。
final _leaderBoardList = StreamController<List<dynamic>>.broadcast();
Run Code Online (Sandbox Code Playgroud)
dispose() {
print('_leaderBoardList disposed');
_leaderBoardList.close();
}
Run Code Online (Sandbox Code Playgroud)
LeaderBoardProvider(
child: MaterialApp(
title: 'Table View Fetch',
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: HomeScreen(),
),
);
Run Code Online (Sandbox Code Playgroud)
Widget build(BuildContext context) {
print(' ListView fetch Build called');
final bloc = LeaderBoardProvider.of(context);
bloc.fetchLeaderBoards();
return WillPopScope(
onWillPop: () async {
//bloc.dispose();
return true;
},
child: bodyStack(context, bloc),
);
}
Run Code Online (Sandbox Code Playgroud)
第一个问题,假设我创建一个广播流并删除“WillPopScope”中的代码处理,那么一切都会按预期工作,但我认为,这样,我的 Bloc 就可以为应用程序生命周期保留内存。
第二个问题 …
我想知道,如何保存我在多个屏幕中使用的数据。我们应该在颤振中使用单例设计模式吗?
假设我使用 BLoC 模式制作登录模块,例如https://github.com/adamjohnlea/Flutter-Login-With-BLoC-Pattern。
现在,如果对于对服务器的每个请求,我都需要发送电子邮件和密码。
供应商代码:
import 'package:flutter/material.dart';
import 'bloc.dart';
class Provider extends InheritedWidget {
final bloc = new Bloc();
Provider({Key key, Widget child})
: super(key: key, child: child);
bool updateShouldNotify(_) => true;
static Bloc of(BuildContext context) {
return (context.inheritFromWidgetOfExactType(Provider) as Provider).bloc;
}
}
Run Code Online (Sandbox Code Playgroud)
区块代码:
import 'validators.dart';
import 'package:rxdart/rxdart.dart';
class Bloc extends Object with Validators {
final _email = BehaviorSubject<String>();
final _password = BehaviorSubject<String>();
// retrieve data from stream
Stream<String> get email => _email.stream.transform(validateEmail);
Stream<String> get password => …Run Code Online (Sandbox Code Playgroud) 需要知道我是否可以在不使用第三方库的情况下从 Stream 获取最后一个值。
首先?我尝试的方式是,当我可以将值发送到“changeEmail”中的流时,我可以将 newValue 存储在我的 BLoC 中的某个变量中。这是正确的吗?
我尝试的第二种方法是添加一个监听器,它也可以完成与上面相同的工作,我需要将 newValue 存储在某个变量中。
我有 SteamController:
final _emailController = StreamController<String>.broadcast();
有 gitter:
Stream<String> get email => _emailController.stream; // getting data from stream
get changeEmail => _emailController.sink.add; // sending data to stream
我已经为容器实现了缩放手势。另外,我添加了 onHorizontalDragUpdate 和 onVerticalDragUpdate。但是当我尝试添加两者时,我收到一个异常,说无法使用 Scale 手势实现两者。即使对于平移手势,它也会抛出相同的异常。下面是我的代码:
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' hide Colors;
import 'dart: math' as math;
class HomeScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<HomeScreen> {
double _scale = 1.0;
double _previousScale;
var yOffset = 400.0;
var xOffset = 50.0;
var rotation = 0.0;
var lastRotation = 0.0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.amber,
body: Stack(
children: <Widget>[
stackContainer(),
],
),
);
}
Widget stackContainer() {
return Stack( …Run Code Online (Sandbox Code Playgroud) 我需要根据 Id 过滤数据库。顶部有搜索栏,说明“输入查询以过滤列表”。如何查询以获取在 RealmDB 浏览器中过滤的某些特定 id。
我的数据库网址:https : //i.stack.imgur.com/G1iXY.png
我想制作一个可以拖动,缩放和旋转的容器。我能够实现变焦。下面是我的代码:
//variable declaration
double _scale = 1.0;
double _previousScale;
var yOffset = 400.0;
var xOffset = 50.0;
var rotation = 0.0;
var lastRotation = 0.0;
Run Code Online (Sandbox Code Playgroud)
//构建方法
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Center(
child: GestureDetector(
onScaleStart: (scaleDetails) {
_previousScale = _scale;
print(' scaleStarts = ${scaleDetails.focalPoint}');
},
onScaleUpdate: (scaleUpdates){
//ScaleUpdateDetails
rotation += lastRotation - scaleUpdates.rotation;
lastRotation = scaleUpdates.rotation;
print("lastRotation = $lastRotation");
print(' scaleUpdates = ${scaleUpdates.scale} rotation = ${scaleUpdates.rotation}');
setState(() => _scale = _previousScale * scaleUpdates.scale);
},
onScaleEnd: …Run Code Online (Sandbox Code Playgroud) 我有用 Matrix4 初始化的 ValueNotifier。我可以改变我的看法。现在我想以某种方式将 ValueNotifier 的当前值保存在 SQLite 中,并再次在加载时使用保存的 Matrix4 值初始化我的 ValueNotifier。下面是代码:
ValueNotifier<Matrix4> notifier = ValueNotifier(Matrix4.identity());
MatrixGestureDetector(
onMatrixUpdate: (matrix, translationMatrix, scaleMatrix, rotationMatrix) {
notifier.value = matrix;
},
child: AnimatedBuilder(animation: notifier,
builder: (context, child) {
return Transform(
transform: notifier.value,
child: Container(
width: width,
height: height,
color: Colors.yellow,
),
);
}),
)
Run Code Online (Sandbox Code Playgroud) 我有一个带有 UIView (V1) 和 UILabel(L1) 的垂直 UIStackView(S1)。UIView 包含水平 StackView(S2) 和 ImageView 以及垂直 StackView(S3),以将标签显示在另一个标签下方。
现在,当我隐藏顶视图(即 V1)时,我的标签占据了预期的完整高度。但我希望堆栈视图压缩以仅显示标签(L1)内容。但就我而言,它并没有减少宽度。
这是我启动和隐藏 V1 时的 ViewTree 和快照。