123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'pages/NewsListPage.dart';
- import 'pages/TweetsListPage.dart';
- import 'pages/DiscoveryPage.dart';
- import 'pages/my_info_page.dart';
- import './widgets/MyDrawer.dart';
- void main() {
- runApp(MyOSCClient());
- }
- class MyOSCClient extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => MyOSCClientState();
- }
- class MyOSCClientState extends State<MyOSCClient> {
- int _tabIndex = 0;
- final tabTextStyleNormal = TextStyle(color: const Color(0xff969696));
- final tabTextStyleSelected = TextStyle(color: const Color(0xff63ca6c));
- var tabImages;
- var _body;
- var appBarTitles = ['资讯', '动弹', '发现', '我的'];
- Image getTabImage(path) {
- return Image.asset(path, width: 20.0, height: 20.0);
- }
- void initData() {
- if (tabImages == null) {
- tabImages = [
- [
- getTabImage('images/ic_nav_news_normal.png'),
- getTabImage('images/ic_nav_news_actived.png')
- ],
- [
- getTabImage('images/ic_nav_tweet_normal.png'),
- getTabImage('images/ic_nav_tweet_actived.png')
- ],
- [
- getTabImage('images/ic_nav_discover_normal.png'),
- getTabImage('images/ic_nav_discover_actived.png')
- ],
- [
- getTabImage('images/ic_nav_my_normal.png'),
- getTabImage('images/ic_nav_my_pressed.png')
- ]
- ];
- }
- _body = IndexedStack(
- children: [
- NewsListPage(),
- TweetsListPage(),
- DiscoveryPage(),
- MyInfoPage()
- ],
- index: _tabIndex,
- );
- }
- TextStyle getTabTextStyle(int curIndex) {
- if (curIndex == _tabIndex) {
- return tabTextStyleSelected;
- }
- return tabTextStyleNormal;
- }
- Image? getTabIcon(int curIndex) {
- if (curIndex == _tabIndex) {
- return tabImages[curIndex][1];
- }
- return tabImages[curIndex][0];
- }
- String getTabTitle(int curIndex) {
- return appBarTitles[
- curIndex]; //Text(appBarTitles[curIndex], style: getTabTextStyle(curIndex));
- }
- @override
- Widget build(BuildContext context) {
- initData();
- return MaterialApp(
- theme: ThemeData(primaryColor: const Color(0xFF63CA6C)),
- home: Scaffold(
- appBar: AppBar(
- title: Text(appBarTitles[_tabIndex],
- style: TextStyle(color: Colors.white)),
- iconTheme: IconThemeData(color: Colors.white)),
- body: _body,
- bottomNavigationBar: CupertinoTabBar(
- items: <BottomNavigationBarItem>[
- BottomNavigationBarItem(icon: getTabIcon(0)!, label: getTabTitle(0)),
- BottomNavigationBarItem(icon: getTabIcon(1)!, label: getTabTitle(1)),
- BottomNavigationBarItem(icon: getTabIcon(2)!, label: getTabTitle(2)),
- BottomNavigationBarItem(icon: getTabIcon(3)!, label: getTabTitle(3)),
- ],
- currentIndex: _tabIndex,
- onTap: (index) {
- setState(() {
- _tabIndex = index;
- });
- },
- ),
- drawer: MyDrawer(),
- ),
- );
- }
- }
|