import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @override State createState() => _HomePageState(); } class _HomePageState extends State { int selectedIndex = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.pinkAccent, title: const Text("APP"), ), body: Row( children: [ MediaQuery.of(context).size.width > 640 ? NavigationRail( leading: MediaQuery.of(context).size.width >= 1008 ? const Text( "Header", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 36), ) : null, onDestinationSelected: (idx) { setState(() { selectedIndex = idx; }); }, destinations: const [ NavigationRailDestination( icon: Icon(Icons.photo_album), label: Text("相册")), NavigationRailDestination( icon: Icon(Icons.person), label: Text("用户")) ], extended: MediaQuery.of(context).size.width >= 1008, selectedIndex: selectedIndex) : const SizedBox( width: 0, ) ], ), bottomNavigationBar: MediaQuery.of(context).size.width <= 640 ? BottomNavigationBar( currentIndex: selectedIndex, onTap: (idx) { setState(() { selectedIndex = idx; }); }, items: const [ BottomNavigationBarItem( icon: Icon(Icons.photo_album), label: "相册"), BottomNavigationBarItem(icon: Icon(Icons.person), label: "用户") ]) : null, ); } }