import 'package:ebabil/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'functions.dart';
import 'pages/language_selection.dart';
import 'pages/settings.dart';
const double button_sized_box_width = 8;
void main() => runApp(HomePage());
class Root extends StatelessWidget {
const Root({ Key ? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.lightBlue),
home: HomePage(),
routes: {
'settings': (context) => Settings()
}
);
}
}
class HomePage extends StatefulWidget {
@override
State<HomePage> createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
],
child: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
backgroundColor: Colors.lightBlue,
title: Text('',
style: TextStyle(color: Colors.white)
),
actions: [
IconButton(
icon: Icon(
Icons.remove_red_eye,
color: Colors.white
),
onPressed: () {
}
)
]
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
NavigationButton('Settings', Icons.settings, 'settings')
]
)
)
)
)
);
}
Widget NavigationButton(String label, IconData icon, String route) {
return ElevatedButton(
onPressed: () => Navigator.pushNamed(context, route),
child: Row(
children: [
Icon(icon),
const SizedBox(width: button_sized_box_width),
Text(label)
]
)
);
}
}
When I press the NavigationButton, it gives an error: Navigator operation requested with a context that does not include a Navigator, in Flutter. Nothing solved this problem. I tried wrapping the app with a builder etc.
I read the answers in StackOverflow, they say you shouldn’t put this into the same level as MaterialPage() widget and so on but nothing solved this problem.