我正在编写一个应用程序,该应用程序通过一个水平方向listView和一个垂直方向在同一视图中显示两个媒体流listView。我目前正在listView使用一些漂亮的样板实现信息的底层,可以在这里找到。
我是新手,相信我的代码有些混乱,总之,我收到了错误;
flutter: The following NoSuchMethodError was thrown building Builder:
flutter: The method 'loadCurrencies' was called on null.
flutter: Receiver: null
flutter: Tried calling: loadCurrencies()
Run Code Online (Sandbox Code Playgroud)
试图执行代码时,发现这里在home_page_view.dart到上述样板。
这是我用来激发错误的代码;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:to_be_deleted/data/crypto_data.dart';
import 'package:to_be_deleted/modules/crypto_presenter.dart';
import 'dart:async';
import 'dart:io';
import 'background.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
), …Run Code Online (Sandbox Code Playgroud) 就像这里,当我点击计时器时,底部导航栏消失了。我想在 flutter 上实现同样的事情。每当我单击底部导航栏项目时,对于新屏幕,底部导航栏不应出现。
这是我的代码。我的底部导航栏有四个项目,我想在路由到新屏幕时隐藏底部导航栏。
class MyFeedScreen extends StatefulWidget {
@override
_MyFeedScreenState createState() => _MyFeedScreenState();
}
class _MyFeedScreenState extends State<MyFeedScreen> {
int _bottomNavIndex = 0;
Widget pageCaller(int index) {
switch (index) {
case 0:
{
return Category();
}
case 1:
{
return Feed();
}
case 3:
{
return Settings();
}
}
}
@override
Widget build(BuildContext context) {
SizeConfig().init(context);
return Scaffold(
body: pageCaller(_bottomNavIndex),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: klogoBlue,
selectedItemColor: Color(0xfff5f5f5),
unselectedItemColor: Color(0xfff5f5f5),
selectedFontSize: 12.0,
type: BottomNavigationBarType.fixed,
currentIndex: _bottomNavIndex,
onTap: (index) {
setState(() { …Run Code Online (Sandbox Code Playgroud) 我在 Flutter 中使用GetX包进行状态管理。我试图根据条件是否成立来显示数据。但出现此错误,提示“类型‘bool’不是类型转换中类型‘RxBool’的子类型”。
下面是我试图展示的代码。感谢帮助。:)
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:github_users/Controllers/status_controller.dart';
import 'package:github_users/Views/show_data.dart';
class HomeScreen extends StatelessWidget {
final statusController = Get.put(StatusController());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar(),
body: Container(
width: double.maxFinite,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
successButton(context),
SizedBox(height: 20),
faliureButton(context),
],
),
),
);
}
//##############################################
//************** Widget Chunks ***************/
//*************** Appbar ************/
PreferredSizeWidget appBar() {
return AppBar(
backwardsCompatibility: true,
brightness: Brightness.dark,
title: Text(
'Github Users',
),
);
}
//*************** Success …Run Code Online (Sandbox Code Playgroud) 我正在努力实现一个使用 Firebase 身份验证和 Google-Sign 的 Flutter 应用程序。我已经成功地让 firebaseauth 正常登录/注销,没有问题。根据 authstate 更改,我定向到主页或登录页面。然后我实现了 Google Sign-in,它会自动将用户登录到 firebase。
这有效,我获得了提示等必要的权限。但是当我点击注销时,应用程序不会重定向到登录屏幕。我正在调用 await firebaseAuth.instance.Signout() ......我相信它确实删除了用户......但它不会重定向。然后,当我再次尝试登录时,没有任何反应。
我尝试了许多不同的登录变体。我似乎无法弄清楚为什么它不会在注销时重定向。
这是我登录 Google 和 firebase 的登录逻辑:
try {
final GoogleSignInAccount googleSignInAccount =
await _googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final FirebaseUser user = await _firebaseAuth.signInWithCredential(credential);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await _firebaseAuth.currentUser();
assert(user.uid == currentUser.uid);
} catch (error) {
print(error);
}
notifyListeners();
}
Run Code Online (Sandbox Code Playgroud)
这是我在 main.dart 中重定向到适当页面的逻辑:
home: …Run Code Online (Sandbox Code Playgroud) 我想在底部导航栏中应用高程。我尝试了海拔属性,但它不起作用。Elevation 属性具有非常微不足道的阴影效果。但根据我的设计,我想要更高的海拔。
我想要以下输出...
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Sample App'),
),
bottomNavigationBar: BottomNavigationBar(
elevation: 10,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit),
title: Text('Test')
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
title: Text('Test')
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
title: Text('Test'),
),
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个有状态小部件,我想将其转换为无状态小部件。我知道如何将无状态小部件转换为有状态小部件。就像无状态小部件一样,有任何快捷方式可用于转换有状态小部件。
我正在使用 Android Studio。谢谢 :)
这是我的简单飞镖代码。
import 'dart:io';
main(){
print("Hello World");
stdout.writeln("Another Hello World");
}
Run Code Online (Sandbox Code Playgroud)
输出:
Hello World //Prints newline by default.
Another Hello World //Also print newline after this.
Run Code Online (Sandbox Code Playgroud)
如果两个函数在打印后都打印一个换行符,那么它们之间有什么区别。
默认情况下,浮动操作按钮位于屏幕右侧。我知道, , 之floatingActionButtonLocation类的和它的属性,但没有一个能帮助我将它移动到屏幕的左侧。endDockedstartDockedcenterDocked
我已经CheckboxListTile在flutter中实现了。默认复选框是方形的。但我需要一个圆形复选框,如下图所示。有什么办法可以做到吗?谢谢您的帮助 :)
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
Widget build(BuildContext context) {
return CheckboxListTile(
title: const Text('Animate Slowly'),
value: timeDilation != 1.0,
onChanged: (bool? value) {
setState(() {
timeDilation = value! ? 10.0 : 1.0;
});
},
secondary: const Icon(Icons.hourglass_empty),
);
}
}
Run Code Online (Sandbox Code Playgroud) 随着RaisedButton和OutlineButton被弃用,flutter 团队引入了一个新的ElevatedButton. 但我不知道如何使 ElevatedButton 的边框像下图一样变圆。
ElevatedButton(
onPressed: () {},
child: Text('Testing'),
),
Run Code Online (Sandbox Code Playgroud)