我想要在不具有appBar的情况下使BottomNavigationBar以及TabBar处于混乱状态,单独地这两个小部件都可以工作,但是当组合在一起时,它说的是在performLayout()期间引发了以下断言:在布局期间,RenderCustomMultiChildLayoutBox对象被赋予了无限大小。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Haate Khori',
theme: ThemeData.light().copyWith(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static List<Widget> _widgetOptions = <Widget>[
Donation(),
Text(
'EXPENSES',
style: optionStyle,
),
Text(
'ACTIVITIES',
style: optionStyle,
),
Text(
'GALLERY',
style: optionStyle,
),
Text(
'DONATE US',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
child: Padding(
padding: const EdgeInsets.all(40.0),
child: SizedBox(
height: 70.0,
),
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.white, Colors.teal], // whitish to gray
stops: [0.0, 0.8]),
),
),
Container(
padding: EdgeInsets.all(10.0),
child: Text(
'Title goes here',
style: TextStyle(color: Colors.white, fontSize: 25.0),
),
color: Colors.teal,
),
_widgetOptions.elementAt(_selectedIndex),
],
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
backgroundColor: Colors.teal,
),
BottomNavigationBarItem(
icon: Icon(Icons.receipt),
title: Text('Expenses'),
backgroundColor: Colors.teal,
),
BottomNavigationBarItem(
icon: Icon(Icons.fiber_smart_record),
title: Text('Activities'),
backgroundColor: Colors.teal,
),
BottomNavigationBarItem(
icon: Icon(Icons.collections),
title: Text('Gallery'),
backgroundColor: Colors.teal,
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
title: Text('Donate us'),
backgroundColor: Colors.teal,
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white,
onTap: _onItemTapped,
),
),
);
}
}
class Donation extends StatefulWidget {
@override
_DonationState createState() => _DonationState();
}
class _DonationState extends State<Donation>
with SingleTickerProviderStateMixin {
TabController tabController;
@override
void initState() {
// TODO: implement initState
super.initState();
tabController = TabController(length: 2, vsync: this);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: Column(
children: <Widget>[
SizedBox(
height: 10.0,
),
TabBar(
labelColor: Colors.teal,
controller: tabController,
tabs: <Widget>[
Tab(
child: Text('Tab1'),
),
Tab(
child: Text('Tab2'),
)
],
),
Expanded(
child: Container(
child: TabBarView(
controller: tabController,
children: <Widget>[
Text(
'Hello',
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
),
Text(
'World',
style: TextStyle(
fontSize: 20.0,
),
textAlign: TextAlign.center,
),
],
),
),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:transportWeb/provider/dimensions.dart';
import 'package:transportWeb/screens/mainScreenViews/aboutUs.dart';
import 'package:transportWeb/screens/mainScreenViews/contactUs.dart';
import 'package:transportWeb/screens/mainScreenViews/home.dart';
import 'package:url_launcher/url_launcher.dart';
import '../constants.dart';
class MainScreen extends StatefulWidget {
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen>
with SingleTickerProviderStateMixin {
TabController _tabController;
var _currentDateTime = DateTime.now();
var _currentHours;
@override
void initState() {
super.initState();
_currentHours = _currentDateTime.hour;
print(_currentHours);
_tabController = TabController(length: 3, vsync: this, initialIndex: 1);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
_tabController.dispose();
}
@override
Widget build(BuildContext context) {
Dimensions(context);
return Scaffold(
floatingActionButton: FloatingActionButton(
tooltip: "Request Call",
backgroundColor: Colors.deepPurpleAccent,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(
"Enter your Phone no",
style: kh3,
),
);
},
);
},
child: Icon(
Icons.phone,
color: Colors.white,
size: 30,
),
),
body: ListView(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 0),
height: 70,
decoration: BoxDecoration(
color: Colors.transparent,
border: Border(
bottom: BorderSide(
color: Colors.grey.shade200,
width: 3,
),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 15),
child: RichText(
text: TextSpan(
style: kh2.copyWith(letterSpacing: 10),
children: <TextSpan>[
TextSpan(text: "JSSR "),
TextSpan(text: "Road"),
TextSpan(
text: "L",
style: kh2.copyWith(color: Colors.red),
),
TextSpan(text: "ines"),
],
),
),
),
Expanded(
child: SizedBox(
width: 0,
height: 0,
),
),
TabBar(
isScrollable: true,
indicatorColor: Colors.black,
indicatorSize: TabBarIndicatorSize.label,
labelColor: Colors.black,
unselectedLabelColor: Colors.grey.withOpacity(0.6),
controller: _tabController,
tabs: [
Tab(
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
"HOME",
style: kh5,
),
),
),
Tab(
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
"ABOUT US",
style: kh5,
),
),
),
Tab(
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
"CONTACT US",
style: kh5,
),
),
),
],
),
GestureDetector(
onTap: () {
launch(
"https://pub.dev/packages/url_launcher#-installing-tab-");
},
child: Container(
margin: EdgeInsets.only(left: 15, bottom: 12),
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.deepPurpleAccent,
),
child: Text(
"DOWNLOAD APP",
style: kh5.copyWith(color: Colors.white),
),
),
),
],
),
),
Container(
width: double.maxFinite,
height: double.maxFinite,
child: TabBarView(
controller: _tabController,
children: [
Home(),
AboutUs(),
ContactUs(),
],
),
)
],
),
);
}
}