Testing/lib/screens/home_screen.dart
2020-06-27 18:46:23 +07:00

82 lines
2.7 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:testapp/config.dart';
import 'package:testapp/screens/business_sreeen.dart';
import 'package:testapp/widgets/home_tabbar_view_widget.dart';
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: Config.categories.length,
initialIndex: 1,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text('News'),
centerTitle: true,
bottom: TabBar(
isScrollable: true,
indicatorColor: Colors.white,
// labelPadding: EdgeInsets.only(right: 10),
tabs: Config.categories.map((category){
return Tab(
text: category.title + "" + category.articleCount.toString(),
);
}).toList(),
),
),
body: TabBarView(
children: Config.categories.map((category){
return HomeTabBarViewwidget(category.title);
}).toList()
),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.red,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home, color:Colors.white),
title: Text('Home', style: TextStyle(
color:Colors.white,)
),
),
BottomNavigationBarItem(
icon: Icon(Icons.business, color: Colors.white,),
title: Text('Business', style: TextStyle(
color: Colors.white,fontSize: 18),),
),
BottomNavigationBarItem(
icon: Icon(Icons.school, color: Colors.white,),
title: Text('School', style: TextStyle(
color: Colors.white,fontSize: 18),
),
),
],
currentIndex: 0,
// selectedItemColor: Colors.black,
// unselectedItemColor: Colors.white,
onTap: (index){
if(index== 0){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>HomeScreen()
));
}
else if(index== 1){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>BusinessScreen()
));
}
else if(index== 2){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>BusinessScreen()
));
}
},
),
),
);
}
}