this is public code. Have anybody have the same problem.
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
/// Used with [AdaptiveScaffold.destinations] to define a destination in the
/// navigation.
class AdaptiveScaffoldDestination {
final String title;
final IconData icon;
const AdaptiveScaffoldDestination({
required this.title,
required this.icon,
});
}
/// A widget that adapts to different screen sizes.
///
/// On smaller screens, it displays a [BottomNavigationBar] for navigation and
/// on larger screens, it displays a [NavigationRail] on the left side.
///
/// This widget is responsive to screen size changes and will adapt accordingly.
class AdaptiveScaffold extends StatelessWidget {
/// The title displayed in the AppBar.
final Widget? title;
/// A list of actions to display in the AppBar.
final List<Widget>? actions;
/// The index of the currently selected destination.
final int currentIndex;
/// A list of destinations to be displayed in the navigation.
final List<AdaptiveScaffoldDestination> destinations;
/// The widget to display in the body of the scaffold.
final Widget body;
/// A callback when the navigation index changes.
final ValueChanged<int> onNavigationIndexChange;
/// A floating action button to display.
final FloatingActionButton? floatingActionButton;
/// A floating action button location.
final FloatingActionButtonLocation? floatingActionButtonLocation;
const AdaptiveScaffold({
Key? key,
this.title,
this.actions,
required this.currentIndex,
required this.destinations,
required this.body,
required this.onNavigationIndexChange,
this.floatingActionButton,
this.floatingActionButtonLocation,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final isLargeScreen = screenWidth > 600;
if (isLargeScreen) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Row(
children: [
NavigationRail(
backgroundColor: Colors.white,
selectedIndex: currentIndex,
onDestinationSelected: onNavigationIndexChange,
extended:
screenWidth > 800,
destinations: destinations.map((destination) {
return NavigationRailDestination(
icon: Icon(destination.icon),
selectedIcon: Icon(destination.icon),
label: Text(destination.title),
);
}).toList(),
),
const VerticalDivider(thickness: 1, width: 1),
Expanded(child: body),
],
),
);
} else {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: title != null ? AppBar(title: title, actions: actions) : null,
body: body,
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType
.fixed,
backgroundColor: Colors.white,
currentIndex: currentIndex,
onTap: onNavigationIndexChange,
items: destinations.map((destination) {
return BottomNavigationBarItem(
icon: Icon(destination.icon),
label: destination.title,
);
}).toList(),
),
floatingActionButton: floatingActionButton,
floatingActionButtonLocation: floatingActionButtonLocation,
);
}
}
}
Thank you