import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:momo/material/gallery.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( title: const Text( "App Header", style: TextStyle(fontWeight: FontWeight.bold), ), elevation: 10, ), body: Row( children: [ MediaQuery.of(context).size.width > 640 ? NavigationRail( elevation: 10, backgroundColor: const Color(0xffebf6f5), leading: MediaQuery.of(context).size.width >= 1008 ? const Text( "Side 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, ), Expanded(child: pageList[selectedIndex]) ], ), bottomNavigationBar: MediaQuery.of(context).size.width <= 640 ? BottomNavigationBar( elevation: 10, currentIndex: selectedIndex, onTap: (idx) { setState(() { selectedIndex = idx; }); }, items: const [ BottomNavigationBarItem( icon: Icon(Icons.photo_album), label: "相册"), BottomNavigationBarItem(icon: Icon(Icons.person), label: "用户") ]) : null, ); } } List pageList = [ Gallery(), Scaffold( body: Placeholder(), ) ];