赞
踩
- class _RootPageState extends State<RootPage> {
- final List<Widget>_pages = [Scaffold(
- appBar: AppBar(title: Text("微信"),),
- body: const Center(child: Text("微信页面"),),
- ), Scaffold(
- appBar: AppBar(title: Text("通讯录"),),
- body: const Center(child: Text("通讯录界面"),),
- ), Scaffold(
- appBar: AppBar(title: Text("发现"),),
- body: const Center(child: Text("发现界面"),),
- ), Scaffold(
- appBar: AppBar(title: Text("我"),),
- body: const Center(child: Text("我的界面"),),
- )];
- //6.设置当前BarItems的默认选中Item, 当某一个被选中的时候,这个index值会发生变化.
- int _currentIndex = 0;
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Scaffold(
- body: _pages[_currentIndex],
- //2.bottomNavigationBar相当于iOS中的TabBar
- bottomNavigationBar: BottomNavigationBar(...),
- ),
- );
- }
- }
- import 'package:flutter/material.dart';
-
- class ChatPage extends StatefulWidget {
- const ChatPage({Key? key}) : super(key: key);
- @override
- State<ChatPage> createState() => _ChatPageState();
- }
- class _ChatPageState extends State<ChatPage> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text("通讯录"),
- ),
- body: const Center(child:
- Text("通讯录界面"),
- ),
- );
- }
- }
- import 'package:wechat_demo/page/chat_page.dart';
- ....
- final List<Widget>_pages = [ChatPage(),...];
- ....
按照上述方法、依次替换_pages中的其他界面
final List<Widget>_pages = [ const ChatPage(), const FriendsPage(), const DiscoverPage(), const MinePage() ];
1.3 遗留问题
1. 当我们点击NavigationBarItem的时候会存在灰色的水波纹动画,以及高亮的颜色问题
- import 'package:flutter/material.dart';
- import 'rootpage.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: "Flutter Demo",
- theme: ThemeData(
- primarySwatch: Colors.blue,
- //1.高亮颜色问题
- highlightColor: Color.fromRGBO(1, 0, 0,0.0),
- //2.点击后水波纹动画颜色.
- splashColor: Color.fromRGBO(1, 0, 0,0.0),
- ),
- home: RootPage(),
- );}
- }
2.点击后字体变大
- bottomNavigationBar: BottomNavigationBar(
- //选中的文字大小
- selectedFontSize: 12.0,
- //4.如果没有设置相应的type、那么默认情况下BarItem设置的都为白色.设置BarType之后默认为蓝色
- type: BottomNavigationBarType.fixed,
- //5.设置fixed类型后,需要添加一个填充色.这样一个TabBar就设置完毕了.
- fixedColor: Colors.green,
- ...),
android:label="微信"
- ~/wechat_demo2 $ flutter run
- Multiple devices found:
- sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30)
- (emulator)
- iPhone 14 Pro Max (mobile) • 8702647C-F052-4CA5-A758-C7BD3CD49057 • ios •
- com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
- macOS (desktop) • macos • darwin-x64 • macOS 12.6.3 21G419
- darwin-x64
- Chrome (web) • chrome • web-javascript • Google Chrome
- 112.0.5615.137
- [1]: sdk gphone x86 (emulator-5554)
- [2]: iPhone 14 Pro Max (8702647C-F052-4CA5-A758-C7BD3CD49057)
- [3]: macOS (macos)
- [4]: Chrome (chrome)
- Please choose one (To quit, press "q/Q"): 1
-
- Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling
- software rendering with "--enable-software-rendering".
- Launching lib/main.dart on sdk gphone x86 in debug mode...
- Running Gradle task 'assembleDebug'...
- ✓ Built build/app/outputs/flutter-apk/app-debug.apk.
- Installing build/app/outputs/flutter-apk/app-debug.apk... 93.0s⣯
- Syncing files to device sdk gphone x86... 1,848ms
- 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/320163推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。