Мне нужна помощь с обновлением текста на панели приложений, чтобы он соответствовал странице, на которой я сейчас нахожусь.
Так что, если я на странице настроек, мне нужно отобразить это в тексте AppBar .
Я добавляю свой код и снимок экрана, чтобы лучше объяснить, чего я хочу достичь.
![First image](https://i.stack.imgur.com/nPMXz.jpg)
![Second Image](https://i.stack.imgur.com/sER1q.jpg)
Main.dart
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// This will change the statusbar text color.
FlutterStatusbarcolor.setStatusBarWhiteForeground(false);
return ChangeNotifierProvider<ThemeChanger>(
create: (_) => ThemeChanger(CustomThemes.lightTheme.copyWith(
textTheme:
CustomThemes.textTheme(CustomThemes.lightTheme.textTheme))),
child: MaterialAppWithTheme(),
);
}
}
class MaterialAppWithTheme extends StatefulWidget {
@override
_MaterialAppWithTheme createState() => _MaterialAppWithTheme();
}
class _MaterialAppWithTheme extends State<MaterialAppWithTheme> {
var appTitle = 'Material Design';
@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeChanger>(context);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: appTitle,
theme: theme.getTheme(),
home: Scaffold(
appBar: AppBar(
title: Text(
appTitle,
style: TextStyle(color: CustomColors().novaWhite),
),
),
body: BlocProvider<MdNavBloc>(
create: (context) => MdNavBloc(),
child: Stack(
children: <Widget>[
BlocBuilder<MdNavBloc, NavigationStates>(
builder: (context, state) {
if (state is DashboardState) {
return DashBoardPage();
} else if (state is ExpensesState) {
return ExpensesPage();
} else if (state is NotificationsState) {
return NotificationsPage();
} else if (state is ErrorsState) {
return ErrorsPage();
} else if (state is SettingsState) {
return SettingsPage();
} else {
return DashBoardPage();
}
},
),
MdDrawer(title: appTitle, updateAppBarTitle: _updateAppBarTitle,),
],
),
),
),
);
}
void _updateAppBarTitle(String newTitle) {
setState(() {
appTitle = newTitle;
});
}
}
MdDrawer.dart
class MdDrawer extends StatefulWidget {
final String title;
final Function(String) updateAppBarTitle;
MdDrawer({Key key, this.title, @required this.updateAppBarTitle}) : super(key: key);
@override
MdDrawerState createState() {
return new MdDrawerState();
}
}
class MdDrawerState extends State<MdDrawer>
with SingleTickerProviderStateMixin {
bool isCollapsed = true;
AnimationController _animationController;
Animation<double> widthAnimation;
int currentSelectedIndex = 0;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 300),
);
widthAnimation = Tween<double>(
begin: Constants.minWidth,
end: Constants.maxWidth,
).animate(_animationController);
}
@override
Widget build(BuildContext context) {
final MdNavBloc bloc = BlocProvider.of<MdNavBloc>(context);
return AnimatedBuilder(
animation: _animationController,
builder: (context, widget) => getWidget(bloc, context, widget),
);
}
Widget getWidget(MdNavBloc bloc, context, widget) {
return Material(
//elevation: 80.0,
child: Container(
width: widthAnimation.value,
//color: drawerBackgroundColor,
color: Theme.of(context).backgroundColor,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
vertical: Constants.containerMargin,
),
child: MdListTile(
title: 'Jaser Jsk',
icon: Icons.person,
animationController: _animationController,
),
),
Divider(color: Colors.grey, height: 20.0),
SizedBox(
height: 8.0,
),
Expanded(
child: ListView.separated(
separatorBuilder: (context, counter) {
return Divider(height: 12.0);
},
itemBuilder: (context, counter) {
return MdListTile(
onTap: () {
widget.updateAppBarTitle(navigationItems[counter].title);
setState(() {
bloc.add(navigationItems[counter].navigationEvent);
currentSelectedIndex = counter;
isCollapsed = !isCollapsed;
_animationController.reverse();
});
},
isSelected: currentSelectedIndex == counter,
title: navigationItems[counter].title,
icon: navigationItems[counter].icon,
animationController: _animationController,
);
},
itemCount: navigationItems.length,
),
),
InkWell(
onTap: () {
setState(() {
isCollapsed = !isCollapsed;
isCollapsed
? _animationController.reverse()
: _animationController.forward();
});
},
child: AnimatedIcon(
icon: AnimatedIcons.menu_close,
progress: _animationController,
color: Theme.of(context).accentColor,
size: 40.0,
),
),
SizedBox(
height: 20.0,
),
],
),
),
);
}
}