我正在尝试Flutter,我正在尝试改变BottomNavigationBar应用程序的颜色,但我所能实现的只是改变了BottomNavigationItem(图标和文本)的颜色.
这是我宣布我的地方BottomNavigationBar:
class _BottomNavigationState extends State<BottomNavigationHolder>{
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: null,
body: pages(),
bottomNavigationBar:new BottomNavigationBar(
items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
icon: const Icon(Icons.home),
title: new Text("Home")
),
new BottomNavigationBarItem(
icon: const Icon(Icons.work),
title: new Text("Self Help")
),
new BottomNavigationBarItem(
icon: const Icon(Icons.face),
title: new Text("Profile")
)
],
currentIndex: index,
onTap: (int i){setState((){index = i;});},
fixedColor: Colors.white,
),
);
}
Run Code Online (Sandbox Code Playgroud)
之前我以为我通过canvasColor在我的主应用主题上编辑绿色来解决它,但它搞砸了整个应用程序配色方案:
class MyApp extends StatelessWidget {
// This widget …Run Code Online (Sandbox Code Playgroud) 我试图创建一个没有AppBar的标签栏布局屏幕.我已经在这个链接上提到了解决方案:如何在没有app bar的情况下创建标签栏?但它不适合我.当我将TabBar放入appbar:参数时,以下是我的屏幕的样子:
我的TabBar已经移动到状态栏下方的左上角,并且它全部挤在一个角落里.这几乎就好像根本就没有.
当我使用AppBar类但只传递bottom:参数时会发生什么:
TabBar顶部有一个丑陋的空间,显然是AppBar标题.这是我的代码:
return new Scaffold(
appBar: new TabBar(
tabs: widget._tabs.map((_Page page){
return Text(page.tabTitle);
}).toList(),
controller: _tabController,
isScrollable: true,
),
backgroundColor: Colors.white,
body: new TabBarView(
controller: _tabController,
children: widget._tabs.map((_Page page){
return new SafeArea(
top:false,
bottom: false,
child: (page.page == Pages.cart?new CartHomeScreen():_lunchesLayout())
);
}).toList()
),
);
Run Code Online (Sandbox Code Playgroud)
如何在没有顶部的空间的情况下使用TabBar,是否可以使两个标签项及其指示器伸展并填充侧面空间?
我有一个堆栈中的小部件,所以我想将我的按钮栏放在堆栈的底部中心,但没有任何作用.小部件只是粘在左侧.这是我的代码.
new Positioned(
bottom: 40.0,
child: new Container(
margin: const EdgeInsets.all(16.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Align(
alignment: Alignment.bottomCenter,
child: new ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
new OutlineButton(
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new LoginPage()));
},
child: new Text(
"Login",
style: new TextStyle(color: Colors.white),
),
),
new RaisedButton(
color: Colors.white,
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) =>
new RegistrationPage()));
},
child: new Text(
"Register",
style: new TextStyle(color: Colors.black),
), …Run Code Online (Sandbox Code Playgroud) 我正在尝试Flutter,我的应用程序在模拟器和真实设备上响应非常慢.我收到这样的警告
跳过51帧!应用程序可能在其主线程上做了太多工作.
我知道Dart是一种单线程编程语言,在Android中,我曾经用new Thread();异步的旧块来解决这个问题.我试图在Flutter中应用相同的内容,然后阅读Future await async和排序,但是当您从互联网上读取数据时,示例似乎正在解决.我的应用程序在这个阶段没有在线阅读任何内容,当我的屏幕有进度对话框,当我打开一个新的屏幕/页面,以及应用程序上的每个动画时,我都会获得跳过的x帧.以下是我遇到问题的类的示例:
_buildContent(){
return new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new InkWell(
onTap: (){
Navigator.push(context, new MaterialPageRoute(builder:
(context) => new LoginScreen()));
},
child: new Container(
height: 150.0,
width: 150.0,
child: new Image.asset("images/logo.png", fit: BoxFit.cover,),
),
),
new Container(
margin: const EdgeInsets.all(16.0),
child: new CircularProgressIndicator(
value: null,
strokeWidth: 1.0,
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.white
)
),
)
],
);
}
Run Code Online (Sandbox Code Playgroud)
我假设跳过的x帧警告是由进度对话框引起的?我有另一个屏幕(登录屏幕),在打开时将小部件动画到位,动画移动得很慢,我可以逐字地看到每个帧都被渲染.是否有在线教程可以帮助解决这个问题或者只是了解Dart的异步编程?
我看到有很多关于如何使用flutter上传图像到firebase存储的例子,但没有关于实际下载/读取/显示已经上传的图像的内容.
在Android中,我只是用来Glide显示图像,我如何在Flutter中这样做?我是否使用NetworkImage该类,如果是,我如何首先获取存储在存储中的图像的URL?
我需要使用Flutter应用程序在添加到Firestore的新文档上添加服务器端时间戳.我看到我应该使用,FieldValue.serverTimestamp但我不知道在哪里可以找到它.
我需要一个没有appbar的布局,所以最明显的方法就是省略appbar标签,Scaffold但是如果我这样做,内容会在状态栏下面,如下所示:
正如你所看到的那样,我的容器是蓝色的,从状态栏的下方开始,不应该是这种情况,所以我不得不手动设置容器的边缘,这不是很好,这是结果:
我有这种感觉,设备可能具有不同高度的状态栏,因此将我的上边距设置为固定大小可能无法在其他设备上正确呈现.是否有一种方法可以让我的内容自动定位在状态之下,就好像它位于AppBar状态栏下方.
这是我的脚手架代码:
return new Scaffold(
body: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new HeaderLayout(),
],
),
);
Run Code Online (Sandbox Code Playgroud)
这是我的标题容器:
class HeaderLayout extends StatelessWidget{
@override
Widget build(BuildContext context) {
return new Container(
color: Colors.blue,
margin: const EdgeInsets.only(top: 30.0),
child: new SizedBox(
height: 80.0,
child: new Center(
child: new Text(
"Recommended Courses",
style: new TextStyle(color: Colors.white),
),
),
)
);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个聊天应用程序,并且试图以相反的方式实现RecyclerView的无尽滚动,例如从底部开始并向上滚动,直到到达顶部时才加载更多内容。
当用户打开聊天屏幕时,该应用会获取最后20条消息,并且默认情况下滚动到底部。当用户向上滚动时,我想从服务器获取更多消息。
以下是我正在测试的通用无穷滚动代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layoutManager = new LinearLayoutManager(this);
recyclerView = (RecyclerView)findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
adapter = new RecyclerViewAdapter<String, ItemViewHolder>(String.class,R.layout.item,ItemViewHolder.class,list) {
@Override
protected void populateViewHolder(ItemViewHolder viewHolder, String model, int position) {
if(model != null){
viewHolder.textView.setText(model);
}
}
};
recyclerView.setAdapter(adapter);
recyclerView.setOnScrollListener(new EndlessReverseRecyclerViewScrollListener(layoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
loadMore();
}
});
loadInit();
}
private void loadInit(){
for(int x = 0; x < 20;x++){
list.add(list.size()+": "+getRandomString(8));
adapter.notifyDataSetChanged();
}
layoutManager.scrollToPosition(list.size() -1);
}
private void …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用创建一个新闻提要,当我向下滚动时,数据是从 Firestore 获取的。一旦我向上滚动,列表视图就会直接捕捉到最顶部,跳过中间的所有其他项目。如果我使用静态数据加载列表视图,列表视图工作正常,但是当我从 Firestore 提取数据时,问题再次出现。我不确定是什么导致了这种行为。
这是我的代码
return StreamBuilder(
stream: Firestore.instance.collection(Constants.NEWS_FEED_NODE)
.document("m9yyOjsPxV06BrxUtHdp").
collection(Constants.POSTS_NODE).orderBy("timestamp",descending: true).snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator(),);
if (snapshot.data.documents.length == 0)
return Container();
//after getting the post ids, we then make a call to FireStore again
//to retrieve the details of the individual posts
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (_, int index) {
return FeedItem2(feed: Feed.fireStore(
snapshot: snapshot.data.documents[index]),);
});
},
);
Run Code Online (Sandbox Code Playgroud) 如何实现一致的项目选择RecyclerView?我完全了解了RecyclerView回收旧观点和不观看的观点.我的问题是我有一个项目列表,每个项目上都有一个图标,当点击一个项目时,图标会改变颜色.我设法实现了所有这一切,但我刚刚意识到,当我向下滚动列表时,其他项目的图标也发生了变化,当我滚动回到我点击的项目时,图标不再出现在"点击"中颜色".
有谁知道如何跟踪所选项目?我一直看到一些叫做的东西SparseBooleanArray,但我不确定如何实现它.
这是我的适配器代码:
public class TableRVAdapter extends RecyclerView.Adapter<TableRVAdapter.TableHolder> {
List<Tables> tableList;
private SparseBooleanArray selectedItems;
public TableRVAdapter(List<Tables> tableList)
{
this.tableList = tableList;
selectedItems = new SparseBooleanArray();
// setHasStableIds(true);
}
class TableHolder extends RecyclerView.ViewHolder
{
TextView tableTV;
CardView tableCV;
View circle;
View parentView;
TableHolder(final View itemView)
{
super(itemView);
tableTV = (TextView)itemView.findViewById(R.id.tableTV);
tableCV = (CardView)itemView.findViewById(R.id.tableCV);
circle = itemView.findViewById(R.id.statusCircle);
itemView.setClickable(true);
parentView = itemView;
tableCV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
circle.setBackgroundResource(R.drawable.circle);
}
});
}
/*
@Override …Run Code Online (Sandbox Code Playgroud)