gpt4 book ai didi

android - 选项卡未显示在 flutter 中

转载 作者:IT王子 更新时间:2023-10-29 07:00:23 24 4
gpt4 key购买 nike

您好,我正在尝试在 flutter 中构建一个应用程序。我想在屏幕上显示标签。我正在尝试如下所示,但它不显示标签。

有谁知道这是什么原因吗?

class DashboardScreen extends StatelessWidget {
Widget bodyData() => SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
),
SizedBox(
height: 10.0,
),
],
),
),
);

@override
Widget build(BuildContext context) {
return CommonScaffold(
appTitle: "Pay",
showDrawer: true,
bodyData: bodyData(),
);
}
}

当我有以下代码时,它会正确显示文本。

  Widget bodyData() => SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Text(
"Pay Your Bills",
style:
TextStyle(fontWeight: FontWeight.w700, fontSize: 20.0),
),
),
),
SizedBox(
height: 10.0,
),
],
),
),
);

enter image description here

最佳答案

我不知道您到底想创建什么,但您的代码存在一些问题。您可以检查下面的代码,它适用于选项卡 View 。

import 'package:flutter/material.dart';

void main() {
runApp(MyHomePage());
}

class MyHomePage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: new ThemeData(
accentColor: Colors.blue,
),
home: DashboardScreen(),
);
}
}
class DashboardScreen extends StatelessWidget {
Widget bodyData() =>
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
);


@override
Widget build(BuildContext context) {
return Scaffold(
body: bodyData(),
);
}
}

关于android - 选项卡未显示在 flutter 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51991734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com