Android 连接来自不同来源的颤振代码,例如youtube教程
大家好,我是新来的 为了理解Flutter,我看了很多视频和博客文章。 但总有一个问题: 每一个视频都是关于一个特定的主题,并且都从一个新的颤振项目开始。只要我想继续编写代码,我就不能更改代码 下面我添加了Hanz Müller的代码作为示例。主题导航栏 但现在我想删除图标下的文本,并用文本和图像编辑不同的应用程序页面(正文)。 我无法删除图标下的文本,因为文本不能为“null”。 我无法编辑不同的正文页,因为我找不到位置 我只知道html和css,因为这是一种爱好,现在我搜索我找到body容器的地方:) 非常感谢你的帮助Android 连接来自不同来源的颤振代码,例如youtube教程,android,android-studio,flutter,navigationbar,Android,Android Studio,Flutter,Navigationbar,大家好,我是新来的 为了理解Flutter,我看了很多视频和博客文章。 但总有一个问题: 每一个视频都是关于一个特定的主题,并且都从一个新的颤振项目开始。只要我想继续编写代码,我就不能更改代码 下面我添加了Hanz Müller的代码作为示例。主题导航栏 但现在我想删除图标下的文本,并用文本和图像编辑不同的应用程序页面(正文)。 我无法删除图标下的文本,因为文本不能为“null”。 我无法编辑不同的正文页,因为我找不到位置 我只知道html和css,因为这是一种爱好,现在我搜索我找到body容器
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class Destination {
const Destination(this.title, this.icon, this.color);
final String title;
final IconData icon;
final MaterialColor color;
}
const List<Destination> allDestinations = <Destination>[
Destination('Home', Icons.home, Colors.teal),
Destination('Business', Icons.business, Colors.cyan),
Destination('School', Icons.school, Colors.orange),
Destination('Flight', Icons.flight, Colors.blue)
];
class DestinationView extends StatefulWidget {
const DestinationView({ Key key, this.destination }) : super(key: key);
final Destination destination;
@override
_DestinationViewState createState() => _DestinationViewState();
}
class _DestinationViewState extends State<DestinationView> {
TextEditingController _textController;
@override
void initState() {
super.initState();
_textController = TextEditingController(
text: 'sample text: ${widget.destination.title}',
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('${widget.destination.title} Text'),
backgroundColor: widget.destination.color,
),
backgroundColor: widget.destination.color[100],
body: Container(
padding: const EdgeInsets.all(32.0),
alignment: Alignment.center,
child: TextField(controller: _textController),
),
);
}
@override
void dispose() {
_textController.dispose();
super.dispose();
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with TickerProviderStateMixin<HomePage> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
top: false,
child: IndexedStack(
index: _currentIndex,
children: allDestinations.map<Widget>((Destination destination) {
return DestinationView(destination: destination);
}).toList(),
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (int index) {
setState(() {
_currentIndex = index;
});
},
items: allDestinations.map((Destination destination) {
return BottomNavigationBarItem(
icon: Icon(destination.icon),
backgroundColor: destination.color,
title: Text(destination.title)
);
}).toList(),
),
);
}
}
void main() {
runApp(MaterialApp(home: HomePage(), debugShowCheckedModeBanner: false));
}
导入“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
班级目的地{
const Destination(this.title、this.icon、this.color);
最后的字符串标题;
最终的Iconda图标;
最终材料颜色;
}
常量列表所有目的地=[
目的地('Home',Icons.Home,Colors.teal),
目的地('Business',Icons.Business,Colors.cyan),
目的地(“学校”,图标。学校,颜色。橙色),
目的地('Flight',Icons.Flight,Colors.blue)
];
类DestinationView扩展StatefulWidget{
const DestinationView({Key-Key,this.destination}):super(Key:Key);
最终目的地;
@凌驾
_DestinationViewState createState()=>\u DestinationViewState();
}
类_DestinationViewState扩展状态{
TextEditingController\u textController;
@凌驾
void initState(){
super.initState();
_text控制器=text编辑控制器(
text:'示例文本:${widget.destination.title}',
);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“${widget.destination.title}Text”),
backgroundColor:widget.destination.color,
),
backgroundColor:widget.destination.color[100],
主体:容器(
填充:常数边集全部(32.0),
对齐:对齐.center,
子项:TextField(控制器:_textController),
),
);
}
@凌驾
无效处置(){
_textController.dispose();
super.dispose();
}
}
类主页扩展了StatefulWidget{
@凌驾
_HomePageState createState()=>\u HomePageState();
}
类_HomePageState使用TickerProviderStateMixin扩展状态{
int _currentIndex=0;
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:安全区(
上图:错,
子:IndexedStack(
索引:_currentIndex,
子项:allDestinations.map((目的地){
返回DestinationView(目的地:目的地);
}).toList(),
),
),
底部导航栏:底部导航栏(
currentIndex:_currentIndex,
onTap:(int索引){
设置状态(){
_currentIndex=索引;
});
},
项目:allDestinations.map((目的地){
返回底部导航BarItem(
图标:图标(destination.icon),
背景颜色:destination.color,
标题:文本(destination.title)
);
}).toList(),
),
);
}
}
void main(){
runApp(MaterialApp(主页:HomePage(),debugShowCheckedModeBanner:false));
}
如果要删除图标下的文本,请检查文本
小部件所在的代码
因此,在BottomNavigationBarItem
title: Text(destination.title)
因此,如果您不需要文本
小部件,只需将其替换为容器即可不显示任何内容
title: Text(destination.title)
我建议您阅读代码并理解它。您越了解小部件的构建和呈现方式,就越容易修改它们。如果您想删除图标下的文本,请检查放置小部件的代码 因此,在
BottomNavigationBarItem
title: Text(destination.title)
因此,如果您不需要文本
小部件,只需将其替换为容器即可不显示任何内容
title: Text(destination.title)
我建议您阅读代码并理解它。您越了解小部件的构建和呈现方式,就越容易修改它们。这对我帮助很大。谢谢。我想我可以用同样的方式编辑每个页面的主体部分(按下图标后,另一个页面打开)?我正在寻找小部件构建(BuildContext上下文)删除子项:TextField(controller:_textController),并添加一个容器(),这实际上取决于您试图构建的内容,并且总是有多种方法。我建议将
Text
替换为Container
,因为BottomNavigationBarItem
要求传递title
,否则会抛出错误。您可以通过BottomNavigationBar
替换用于更改页面的支架主体。如果您想在当前页面的顶部打开新页面,则必须使用Navigator。这对我帮助很大。谢谢。我想我可以用同样的方式编辑每个页面的主体部分(按下图标后,另一个页面打开)?我正在寻找小部件构建(BuildContext上下文)删除子项:TextField(controller:_textController),并添加一个容器(),这实际上取决于您试图构建的内容,并且总是有多种方法。我建议将Text
替换为Container
,因为BottomNavigationBarItem
要求传递title
,否则会抛出错误。您可以通过BottomNavigationBar
替换用于更改页面的支架主体。如果要在y顶部打开新页面