feat: 主页面功能
This commit is contained in:
1 parent
91edb73885
commit
f233f1c642
21 files changed
+1295
-104
No files matched your search
@@ -0,0 +1,7 @@
|
||||
|
||||
export 'package:novyronst/common/const/const_color.dart';
|
||||
export 'package:novyronst/common/const/const_string.dart';
|
||||
export 'package:novyronst/common/help/help_image.dart';
|
||||
|
||||
|
||||
export 'package:novyronst/tools/util/app_screen.dart';
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:novyronst/common/help/help_image.dart';
|
||||
import 'package:novyronst/pages/collect/pages/collection_page.dart';
|
||||
import 'package:novyronst/pages/first/pages/first_page.dart';
|
||||
import 'package:novyronst/pages/my/pages/my_page.dart';
|
||||
import 'package:novyronst/pages/play/pages/play_page.dart';
|
||||
import 'package:novyronst/root/lib_export.dart';
|
||||
import 'package:novyronst/tools/widgets/extend_widget.dart';
|
||||
import 'package:novyronst/tools/widgets/novy_com_widget.dart';
|
||||
import 'package:novyronst/tools/widgets/novy_keep_alive.dart';
|
||||
|
||||
class RootPage extends StatefulWidget {
|
||||
const RootPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<RootPage> {
|
||||
|
||||
final _pageController = PageController();
|
||||
final List<Widget> _pages = [
|
||||
NovyKeepAlive(child: FirstPage()),
|
||||
NovyKeepAlive(child: PlayPage()),
|
||||
CollectionPage(),
|
||||
NovyKeepAlive(child: MyPage()),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _pageController,
|
||||
children: _pages,
|
||||
),
|
||||
Positioned(
|
||||
left: 0, right: 0, bottom: 0,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: AppBottomView(
|
||||
onSelectedIndex: (index) {
|
||||
_pageController.jumpToPage(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 底部tabbar
|
||||
class AppBottomView extends StatefulWidget {
|
||||
const AppBottomView({super.key,
|
||||
required this.onSelectedIndex,
|
||||
});
|
||||
|
||||
final Function(int) onSelectedIndex;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _AppBottomViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _AppBottomViewState extends State<AppBottomView> {
|
||||
|
||||
final List<String> _unselectedIcons = [
|
||||
ConstImage.btHomeUnsel, ConstImage.btPlayUnsel,
|
||||
ConstImage.btCollectUnsel, ConstImage.btMineUnsel
|
||||
];
|
||||
final List<String> _selectedIcons = [
|
||||
ConstImage.btHomeSel, ConstImage.btPlaySel,
|
||||
ConstImage.btCollectSel, ConstImage.btMineSel
|
||||
];
|
||||
final List<String> _titles = ['Home', 'Play', 'Collect', 'Me'];
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const double _height = 65;
|
||||
return Container(
|
||||
height: _height,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Stack(
|
||||
children: [
|
||||
HelpImage.asset(ConstImage.appBottom,
|
||||
width: AppScreen.screenWidth-32, height: _height,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Padding(padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: List.generate(_unselectedIcons.length, (index) {
|
||||
return _buildTabItem(_titles[index], index, onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
widget.onSelectedIndex(index);
|
||||
|
||||
});
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabItem(String title, int index, {required Function() onTap}) {
|
||||
String icon = _currentIndex == index ? _selectedIcons[index] : _unselectedIcons[index];
|
||||
Color tcolor = _currentIndex == index ? ConstColor.btGreen : ConstColor.btWhite;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
width: 60, height: 70,
|
||||
child: Column(
|
||||
children: [
|
||||
HelpImage.asset(icon, width: 32, height: 32),
|
||||
const SizedBox(height: 2),
|
||||
NovyText(title, fontSize: 11,
|
||||
color: tcolor,
|
||||
)
|
||||
],
|
||||
)
|
||||
).addInkWell(onTap: onTap);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user