滚动时是否可以更改 Appbar 或 SliverAppbar 的背景?我对SliverAppbaror有这些要求Appbar,但我找不到解决它们的方法。
这是 Appbar 或 SliverAppbar 的第一次出现
这是滚动时 AppBar 或 SliverAppbar 的外观
这是我想要实现的示例
我正在创建一个文本样式模型并使用 getter 来获得使用google_fonts 的文本样式。当我提供财产时会出现此问题fontWeight:。此外,它fontWeight不提供与 GoogleFont 类似的外观。
我已经在另一个项目上进行了测试,使用html renderer. 我已经检查过这个问题,但它不起作用。
风格比较
\n\n\n\n\n\n
flutter doctor -v没有任何问题
Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version\n 10.0.19043.1288], locale en-US)\n \xe2\x80\xa2 Flutter version 2.5.2 at C:\\Tools\\flutter\n \xe2\x80\xa2 Upstream repository https://github.com/flutter/flutter.git \n \xe2\x80\xa2 Framework revision 3595343e20 (3 weeks ago), 2021-09-30 12:58:18 \n -0700\n \xe2\x80\xa2 Engine revision 6ac856380f\n \xe2\x80\xa2 Dart version 2.14.3\nRun Code Online (Sandbox Code Playgroud)\n模型类
\n …我用来CustomPainter创建一个三角形。我想创建一个带边框的三角形。
我的 PaintTriangle 课程:
class PaintTriangle extends CustomPainter {
final Color backgroundColor;
PaintTriangle({
required this.backgroundColor,
});
@override
void paint(Canvas canvas, Size size) {
final y = size.height;
final x = size.width;
final paint = Paint()..color = backgroundColor;
final path = Path()
..moveTo(0, y)
..lineTo((x / 2), (y / y))
..lineTo(x, y);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置密码和电子邮件验证,但收到上述错误。任何帮助将不胜感激。上面的错误出现在main.dart代码中,并且已经在代码中加粗了。
validator.dart 代码
enum FormType { login, register }
class EmailValidator {
static String? validate(String value) {
return value.isEmpty ? "Email can't be empty" : null;
}
}
class PasswordValidator {
static String? validate(String value) {
return value.isEmpty ? "Password can't be empty" : null;
}
}
Run Code Online (Sandbox Code Playgroud)
main.dart 代码
List<Widget>buildInputs() {
return [
TextFormField(
validator: **EmailValidator.validate**,
decoration: InputDecoration(labelText: 'Email'),
onSaved: (value) => _email = value,
),
TextFormField(
validator: **PasswordValidator.validate**,
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
onSaved: (value) => _password = value, …Run Code Online (Sandbox Code Playgroud) 我想为自定义添加连锁反应Container。我已经使用Inkwell和Material小部件来实现此行为,但它不起作用。代码如下:
@override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: (){},
child: Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(18),
color: Colors.deepPurpleAccent,
),
alignment: Alignment.center,
child: Text(
"A box container",
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
结果是:
我还使用了透明颜色Container和紫色,Material如下所示:
@override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.deepPurpleAccent,
child: InkWell(
onTap: () {},
child: Container( …Run Code Online (Sandbox Code Playgroud) 我遇到了有关我的 Flutter 应用程序的问题,我一直在关注 Youtube 上的教程,了解如何在 Flutter 中使用从图库中选择图片以及相机,但无法使图像选择器功能正常工作。它总是返回错误
“无法使用静态访问来访问实例成员‘pickimage’。
谁能帮忙解决这个问题,因为我有点困惑。先感谢您。
class _LandingScreenState extends State<LandingScreen>{
late File imageFile;
_openGallery() async{
var picture = await ImagePicker.pickImage(source:
ImageSource.gallery);
this.setState(() {
imageFile = picture as File;
});
}
Run Code Online (Sandbox Code Playgroud) 我是颤振新手,这是我第一次在我的一个项目中实现底部导航栏,但我很困惑为什么它不允许我切换屏幕。不知何故,我可以点击图标,但点击时不会切换页面。
我在 Youtube 的一个教程中得到了这段代码,从视频来看它似乎运行良好。
class NavBar extends StatefulWidget {
static const String route = 'navbar';
const NavBar({Key? key}) : super(key: key);
@override
State<NavBar> createState() => _NavBarState();
}
class _NavBarState extends State<NavBar> {
@override
Widget build(BuildContext context) {
int pageIndex = 0;
final AuthController auth = locator<AuthController>();
final List<Widget> pages = [
const HomeScreen(),
const ArtistsScreen(),
const ChatHomeScreen(),
const ProfileScreen(),
];
return Scaffold(
body: pages[pageIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: const Color(0xffE28D00),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white70,
currentIndex: pageIndex,
elevation: 3,
showUnselectedLabels: …Run Code Online (Sandbox Code Playgroud) 我一直致力于提供两个下拉按钮,以便用户轻松选择汽车型号及其各自的品牌。下面是我拥有的静态列表的代码片段。任何反馈都将受到高度赞赏。
final List<String> carModel = [
'Audi',
'BMW',
'Chevrolet',
'Chrysler',
'Daihatsu',
'Ford',
'Hino',
'Honda',
'Isuzu',
'Jaguar',
'Jeep',
'Landrover',
'Lexus',
'Mazda',
'Mercedes',
'Mitsubishi',
'Nissan',
'Peugeot',
'Porsche',
'Subaru',
'Suzuki',
'Toyota',
'UD',
'Volkswagen',
'Volvo'
];
final List<String> audiMake = [
'A3',
'A4',
'A5',
'A6',
'A7',
'A8',
'Q3',
'Q5',
'Q7',
'Q8',
'R8',
'TT',
];
final List<String> bmwMake = [
'1 Series',
'2 Series',
'3 Series',
'4 Series',
'5 Series',
'6 Series',
'7 Series',
'8 Series',
'M2',
'M3',
'M4',
'M5',
'M6',
'X1',
'X2',
'X3',
'X4', …Run Code Online (Sandbox Code Playgroud) \n\n错误:\'ModalBottomSheetRoute\' 是从 \'package:flutter/src/material/bottom_sheet.dart\' 和 \'package:modal_bottom_sheet/src/bottom_sheet_route.dart\' 导入的。\n../\xe2\x80 \xa6/src/material_with_modal_page_route.dart:4\n导入 \'../modal_bottom_sheet.dart\';\n^^^^^^^^^^^^^^^^^^^^^
\n
: 错误: \'ModalBottomSheetRoute\' 是从 \'package:flutter/src/material/bottom_sheet.dart\' 和 \'package:modal_bottom_sheet/src/bottom_sheet_route.dart\' 导入的。\n../\xe2\ x80\xa6/bottom_sheets/material_bottom_sheet.dart:28\n.push(ModalBottomSheetRoute(\n^^^^^^^^^^^^^^^^^^^^^^\n: 错误: 类型的值无法从返回类型为“Future<T?>”的异步函数返回“Object?”。\n../\xe2\x80\xa6/bottom_sheets/material_bottom_sheet.dart:50
\n“Object”来自“dart:core”。
\n\'Future\' 来自 \'dart:async\'。\n返回结果;
\n ^\nRun Code Online (Sandbox Code Playgroud)\n: 错误: \'ModalBottomSheetRoute\' 是从 \'package:flutter/src/material/bottom_sheet.dart\' 和 \'package:modal_bottom_sheet/src/bottom_sheet_route.dart\' 导入的。\n../\xe2\ x80\xa6/bottom_sheets/bar_bottom_sheet.dart:102\n.push(ModalBottomSheetRoute(\n^^^^^^^^^^^^^^^^^^^^^^\n: 错误: 类型的值无法从返回类型为“Future<T?>”的异步函数返回“Object?”。\n../\xe2\x80\xa6/bottom_sheets/bar_bottom_sheet.dart:125
\n目标 kernel_snapshot 失败:异常
\n失败:构建失败并出现异常。
\n其中:\n脚本\'/Users/vannak/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle\'行:1151
\n出了什么问题:\n任务 \':app:compileFlutterBuildDebug\' 执行失败。
\n\n\n进程\'command\'/Users/vannak/Documents/flutter/bin/flutter\'\'以非零退出值1完成
\n
\n …
flutter ×10
dart ×7
bottom-sheet ×1
button ×1
flutter-web ×1
gridview ×1
imagepicker ×1
validation ×1