Flutter 小部件问题-显示不符合我的要求
我从学习飞镖和颤振开始。为此,我尝试编写代码。 现在,我一直在使用我创建的小部件。 下面您将看到代码 我创建了一个可重用的:Flutter 小部件问题-显示不符合我的要求,flutter,widget,flutter-layout,Flutter,Widget,Flutter Layout,我从学习飞镖和颤振开始。为此,我尝试编写代码。 现在,我一直在使用我创建的小部件。 下面您将看到代码 我创建了一个可重用的: 抽屉:这个管用 应用程序栏:这个有效 listview:这个有效 底部导航栏:这个有效 标签栏:这个有效 我的问题是,当我调用一个页面时,我想调用每个小部件的类。 抽屉&应用程序栏&列表视图=>它可以工作。它们都陈列得很好。 如果我将底部条添加到它,那么,我只看到底部条。我想剩下的都藏在下面了 请允许我让你看看下面的源代码,让我知道我遗漏了什么? 非常感谢 //=
- 抽屉:这个管用
- 应用程序栏:这个有效
- listview:这个有效
- 底部导航栏:这个有效
- 标签栏:这个有效
//==============This is the code for myAppBar=============================
import 'package:flutter/material.dart';
//Creation d'un Widget AppBar qui sera importé dans un Scaffold des autres pages
class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
@override
final Size preferredSize;
final String title;
CustomAppBar(
this.title,
{ Key key,}) : preferredSize = Size.fromHeight(50.0),
super(key: key);
@override
Widget build(BuildContext context) {
return AppBar(
title: Text(
title,
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.blue,
elevation: 5,
automaticallyImplyLeading: true,
);
}
}
//==========================end of myAppBar=======================
//===============================myBottomNavigationBar=======================
进口“包装:颤振/材料.省道”;
/或const UTILIS ButoMutualBar倒入IdqQuoi Qui塞尔特Chank iCon
const String buttone=“一”;
常量字符串按钮two=“两”;
const String buttonThree=“三”;
常量字符串buttonFour=“四”;
const String buttoneicon=“assets/icons/1.png”;
const String buttonTwoIcon=“assets/icons/2.png”;//修改器更改器图标
const String buttonThreeIcon=“assets/icons/3.png”;
const String buttonFourIcon=“assets/icons/4.png”;//修改器更改器图标
//创建小部件AppBar qui sera importédans un Scaffold des autres页面
类应用程序扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主页:MyBottomBar(),
);
}
}
类MyBottomBar扩展了StatefulWidget{
@凌驾
状态createState(){
返回_MyBottomBarState();
}
}
类MyBottomBarState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
底部导航栏:底部导航栏(
currentIndex:0,//点击新选项卡时将设置此项
项目:[
底部导航气压计(
图标:约束框(
约束:BoxConstraints(
最小宽度:iconSize+5,
最小高度:iconSize+5,
最大宽度:iconSize+5,
最大高度:iconSize+5,
),
子项:Image.asset(按钮图标,fit:BoxFit.cover),
),
标题:新文本(无),
),
底部导航气压计(
图标:约束框(
约束:BoxConstraints(
最小宽度:iconSize+5,
最小高度:iconSize+5,
最大宽度:iconSize+5,
最大高度:iconSize+5,
),
子项:Image.asset(buttonTwoIcon,fit:BoxFit.cover),
标题:新文本(按钮二),
),
底部导航气压计(
图标:约束框(
约束:BoxConstraints(
最小宽度:iconSize+5,
最小高度:iconSize+5,
最大宽度:iconSize+5,
最大高度:iconSize+5,
),
子项:Image.asset(ButtontThreeIcon,fit:BoxFit.cover),
标题:文本(按钮树)
),
底部导航气压计(
图标:约束框(
约束:BoxConstraints(
最小宽度:iconSize+5,
最小高度:iconSize+5,
最大宽度:iconSize+5,
最大高度:iconSize+5,
),
子项:Image.asset(buttonFourIcon,fit:BoxFit.cover),
标题:文本(buttonFour)
)
],
类型:BottomNavigationBarType.fixed,
),
);
}
/=================================================myBottomNavigationBar的结束=========================
/=====================================myListView============
进口“包装:颤振/材料.省道”;
类MyListView扩展了无状态小部件{
列表项=列表。生成(15,(i)=>“列表项$i”);
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:ListView.builder(
itemCount:listItems.length,
itemBuilder:(上下文,索引){
返回填充(
填充:常数边集全部(10.0),
子:列(
儿童:[
列表砖(
领先:图标(图标。休眠,大小:40,),
标题:专栏(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
文本(“${listItems[index]}”,样式:TextStyle(fontSize:16),
Text('这是子标题',样式:TextStyle(字体大小:14,颜色:Colors.grey),)
],
),
尾随:图标(图标。快进),
),
分隔器()
],
),
);
},
)
);
}
}
//==========================================================我的ListView结束============================
/===========================================myTabBar================
进口“包装:颤振/材料.省道”;
类TabsPage扩展StatefulWidget{
@凌驾
_tabspagentate createState()=>tabspagentate();
}
类_tabspagentate扩展状态{
int _currentIndex=0;
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:IndexedStack(
索引:_currentIndex,
儿童:[
对于(TabNavigationItem.items中的最终tabItem)tabItem.page,
],
),
底部导航栏:底部导航栏(
currentIndex:_currentIndex,
onTap:(int index)=>setState(()=>\u currentIndex=index),
项目:[
for(TabNavigationItem.items中的最后一个tabItem)
底部导航气压计(
图标:tabItem.icon,
标题:tabItem.title,
),
],
),
);
}
}
TabNavi类
//=====================myBottomNavigationBar=======================
import 'package:flutter/material.dart';
//Const utilisées par bottomNavigationBar pour indiquer à quoi sert chaque icones
const String buttonOne = "One";
const String buttonTwo = "two";
const String buttonThree = "three";
const String buttonFour = "Four";
const String buttonOneIcon = "assets/icons/1.png";
const String buttonTwoIcon = "assets/icons/2.png"; // A MODIFIER CHANGER ICONS
const String buttonThreeIcon = "assets/icons/3.png";
const String buttonFourIcon = "assets/icons/4.png";// A MODIFIER CHANGER ICONS
//Creation d'un Widget AppBar qui sera importé dans un Scaffold des autres pages
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyBottomBar(),
);
}
}
class MyBottomBar extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyBottomBarState();
}
}
class _MyBottomBarState extends State<MyBottomBar> {
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0, // this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: ConstrainedBox(
constraints: BoxConstraints(
minWidth: iconSize+5,
minHeight: iconSize+5,
maxWidth: iconSize+5,
maxHeight: iconSize+5,
),
child: Image.asset(buttonOneIcon, fit: BoxFit.cover),
),
title: new Text(buttonOne),
),
BottomNavigationBarItem(
icon: ConstrainedBox(
constraints: BoxConstraints(
minWidth: iconSize+5,
minHeight: iconSize+5,
maxWidth: iconSize+5,
maxHeight: iconSize+5,
),
child: Image.asset(buttonTwoIcon, fit: BoxFit.cover),),
title: new Text(buttonTwo),
),
BottomNavigationBarItem(
icon: ConstrainedBox(
constraints: BoxConstraints(
minWidth: iconSize+5,
minHeight: iconSize+5,
maxWidth: iconSize+5,
maxHeight: iconSize+5,
),
child: Image.asset(buttonThreeIcon, fit: BoxFit.cover),),
title: Text(buttonThree)
),
BottomNavigationBarItem(
icon: ConstrainedBox(
constraints: BoxConstraints(
minWidth: iconSize+5,
minHeight: iconSize+5,
maxWidth: iconSize+5,
maxHeight: iconSize+5,
),
child: Image.asset(buttonFourIcon, fit: BoxFit.cover),),
title: Text(buttonFour)
)
],
type: BottomNavigationBarType.fixed,
),
);
}
/==============================end of myBottomNavigationBar=========================
//========================myListView============
import 'package:flutter/material.dart';
class MyListView extends StatelessWidget {
List<String> listItems = List<String>.generate(15, (i) => "List Item $i");
@override
Widget build(BuildContext context) {
return Scaffold(
body:ListView.builder(
itemCount: listItems.length,
itemBuilder: (context,index){
return Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
ListTile(
leading: Icon(Icons.snooze,size: 40,),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${listItems[index]}', style: TextStyle(fontSize: 16),),
Text('This is sub heading',style: TextStyle(fontSize: 14, color: Colors.grey),)
],
),
trailing: Icon(Icons.fast_forward),
),
Divider()
],
),
);
},
)
);
}
}
//==============================end of myListView============================
//==========================myTabBar================
import 'package:flutter/material.dart';
class TabsPage extends StatefulWidget {
@override
_TabsPageState createState() => _TabsPageState();
}
class _TabsPageState extends State<TabsPage> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: <Widget>[
for (final tabItem in TabNavigationItem.items) tabItem.page,
],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (int index) => setState(() => _currentIndex = index),
items: <BottomNavigationBarItem>[
for (final tabItem in TabNavigationItem.items)
BottomNavigationBarItem(
icon: tabItem.icon,
title: tabItem.title,
),
],
),
);
}
}
class TabNavigationItem {
final Widget page;
final Widget title;
final Icon icon;
TabNavigationItem({
@required this.page,
@required this.title,
@required this.icon,
});
static List<TabNavigationItem> get items => [
TabNavigationItem(
page: Clarify(),
icon: Icon(Icons.home),
title: Text("Home"),
),
TabNavigationItem(
page: Clarify(),
icon: Icon(Icons.shopping_basket),
title: Text("Shop"),
),
TabNavigationItem(
page: Clarify(),
icon: Icon(Icons.search),
title: Text("Search"),
),
];
}
//===============end of myTabBar=============================
//=======Page where I am using the reusable widget===========
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import
var Titre = "HOME";
class Clarify extends StatefulWidget {
@override
_ClarifyState createState() => _ClarifyState();
}
class _ClarifyState extends State<Clarify> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new CustomAppBar(Titre),
drawer: MyMenu(),
body: new FirstTab(),
bottomNavigationBar: MyBottomBar(),
//if I deactivate bootommNavigationBar:MyBottomBar using "//", then, the appBar, the drawer and the tab are displayed. If I am adding the bottomNavigationBar, I only can see the BottomNavigationBar.
);
//
// throw UnimplementedError();
}
}
bottomNavigationBar: MyBottomBar(),
bottomNavigationBar: BottomNavigationBar(
...
import 'package:flutter/material.dart';
import 'package:sof/bnb.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
body: Text("Some Widget"),
bottomNavigationBar: MyBottomBar(),
),
);
}
}
import 'package:flutter/material.dart';
//Const utilisées par bottomNavigationBar pour indiquer à quoi sert chaque icones
const String buttonOne = "One";
const String buttonTwo = "two";
const String buttonThree = "three";
const String buttonFour = "Four";
const String buttonOneIcon = "assets/icons/1.png";
const String buttonTwoIcon = "assets/icons/2.png"; // A MODIFIER CHANGER ICONS
const String buttonThreeIcon = "assets/icons/3.png";
const String buttonFourIcon = "assets/icons/4.png"; // A MODIFIER CHANGER ICONS
//Creation d'un Widget AppBar qui sera importé dans un Scaffold des autres pages
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyBottomBar(),
);
}
}
class MyBottomBar extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyBottomBarState();
}
}
class _MyBottomBarState extends State<MyBottomBar> {
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: 0, // this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: Icon(Icons.ac_unit), title: Text(buttonOne)),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarms), title: Text(buttonTwo)),
],
);
}
}