**當我點擊一個小部件時,螢屏不會改變,直到我再次保存檔案。
這是我單擊小部件時的日志: D/skia ( 5395): Errors: D/skia ( 5395): 鏈接失敗但沒有提供資訊日志 D/skia ( 5395): Shader compiler error D/skia ( 5395) ): ------------------------ D/skia (5395): 錯誤: D/skia (5395): 鏈接失敗但沒有提供資訊日志**
這是代碼
import 'package:flutter/material.dart';
import 'package:flutter_cubit/pages/navpages/bar_item_page.dart';
import 'package:flutter_cubit/pages/navpages/home_page.dart';
import 'package:flutter_cubit/pages/navpages/my_page.dart';
import 'package:flutter_cubit/pages/navpages/search_page.dart';
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
List pages=[
HomePage(),
BarItemPage(),
SearchPage(),
MyPage()
];
int currentIndex=0;
void onTap(int index){
currentIndex=index;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
unselectedFontSize: 0,
selectedFontSize: 0,
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.white,
onTap: onTap,
currentIndex: currentIndex,
selectedItemColor: Colors.black54,
unselectedItemColor: Colors.grey.withOpacity(0.5),
showUnselectedLabels: false,
showSelectedLabels: false,
elevation: 0,
items: [
BottomNavigationBarItem(title: Text("Home"), icon: Icon(Icons.apps)),
BottomNavigationBarItem(title: Text("Bar"), icon: Icon(Icons.bar_chart_sharp)),
BottomNavigationBarItem(title: Text("Search"), icon: Icon(Icons.search)),
BottomNavigationBarItem(title: Text("My"), icon: Icon(Icons.person)),
],
),
);
}
}
uj5u.com熱心網友回復:
你不是在呼叫 setState。因此將 onTap 更改為以下代碼:
void onTap(int index){
setState(() {
currentIndex=index;
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/393790.html
上一篇:如何解決顫振堆疊小部件問題
