could not find a generator for route RouteSettings("org_Item", null) in the _WidgetsAppState - flutter

I´m newbie to flutter and reveice one exception about route, I don't why I am getting this error in the debug console 'could not find a generator for route RouteSettings("org_Item", null) in the _WidgetsAppState.'
provinces_item.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/orgscreen.dart';
class provwidget extends StatelessWidget {
final String id;
final String title;
final String image;
provwidget(this.id, this.title, this.image);
void selectOrg(BuildContext ctx) {
Navigator.of(ctx).pushNamed(orgscreen.routeName);
}
#override
Widget build(BuildContext context) {
return InkWell(
onTap: () => selectOrg(context),
child: Image.asset(image),
);
}
}
main.dart
import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/log_in.dart';
import 'screens/page_view.dart';
import 'screens/log_in.dart';
import 'screens/orgscreen.dart';
void main() async {
runApp(page_view());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
home: const log_in_screen(),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},
);
}
}
orgscreen.dart
import 'package:flutter/material.dart';
class orgscreen extends StatefulWidget {
static const routeName = 'org_Item';
#override
State<orgscreen> createState() => _orgscreenState();
}
class _orgscreenState extends State<orgscreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('ggg')),
body: null,
);
}
}
If someone knows the solution it would be grateful for help, and explaining what was wrong, thanks

Try to remove your home: const log_in_screen(), and for format case use '/org_Item';
title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},
And not sure about your page_view, you can check
runApp(MyApp());

The correct way of define route is use / with it, So change your route to this:
static const routeName = '/org_Item';
when yo do not run your main class (MyApp) in your runApp, it can not define that route, so also correct this:
runApp(MyApp());
last thing when you define / this in your routes, you should not use home property of MaterialApp, so remove home: const log_in_screen(), and your final MaterialApp should look like this:
MaterialApp(
title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},
)

Related

parameter getPages isnt defined

im trying to learn using get but im having a little bit of problems where getPages isnt defined, this is my code , i hope you can help me. I know it is not defined but isnt it includes in the package that i import?
import 'package:flutter/material.dart';
import 'package:todos/routes.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: "Poppins"
),
initialRoute: GetRoutes.login,
getPages: GetRoutes.routes, //This line here isnt defined
);
}
}
and this is my GetRoutes class
class GetRoutes{
static const String login = "/login";
static const String signup = "/signup";
static const String home = "/home";
static List<GetPage> routes = [
GetPage(
name: GetRoutes.login,
page: () => const LoginScreen()
),
GetPage(
name: GetRoutes.signup,
page: () => const SignupScreen(),
),
];
}
Change MaterialApp to GetMaterialApp
#override
Widget build(BuildContext context) {
return GetMaterialApp(
Also you can use just MaterialApp with routes like
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue, fontFamily: "Poppins"),
initialRoute: GetRoutes.login,
routes: GetRoutes.routes,
);
}
}
class GetRoutes {
static const String login = "/login";
static const String signup = "/signup";
static const String home = "/home";
static var routes = {
login: (_) => LoginPage(),
// add others
};
}

Splash screen with auto route

I want to implement an animated splash screen
Generally in MaterialApp, we have a property called home but when I use autoroute (MaterialApp.router) am unable to find a home in it then how can I implement a splash screen with autoroute
package link
main.dart file
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: const <Locale>[Locale('en')],
path: 'assets/i18n',
fallbackLocale: const Locale('en'),
child: const App(),
),
);
}
class Appp extends StatefulWidget {
const Appp({Key? key}) : super(key: key);
#override
State<Appp> createState() =>
_ApppState();
}
class _ApppState extends State<Appp> {
final _themeStore = ThemeStore();
final _appRouter = AppRouter();
#override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
title: 'App',
theme: _themeStore.selectedThemeData,
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}
First You have to show the Splash screen and then for the next screen, you can use MaterialApp.router
eg.
void main() {
runApp(SplashScreen());
}
class SplashScreen extends StatelessWidget {
SplashScreen({Key? key}) : super(key: key);
final _appRouter = AppRouter();
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Splash App',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: AnimatedSplashScreen(
animationDuration: const Duration(seconds: 2),
splashTransition: SplashTransition.slideTransition,
splash: Icons.code,
nextScreen: MaterialApp.router(
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(),
),
),
);
}
}
Packages Used:
auto route
animated_splash_screen

Can't change flutter theme color

I need to change the flutter theme color, but when I tried then run my app it's show nothing to change. I don't know why.
I have tried this way:
import 'package:flutter/material.dart';
import 'pages/home_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
themeMode: ThemeMode.dark,
theme: ThemeData(primarySwatch: Colors.deepPurple),
darkTheme: ThemeData(
brightness: Brightness.dark, primarySwatch: Colors.deepPurple),
);
}
}
when I change like this way, then still show me default blue color.
flutter version: 2.2.1
Any suggestion please.
with this code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "Title",
theme: ThemeData(primarySwatch: Colors.deepPurple),
darkTheme: ThemeData(
brightness: Brightness.dark, primarySwatch: Colors.deepPurple),
home: Test(),
);
}
}
class Test extends StatelessWidget {
const Test({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SomeText"),
),
body: Center(child: Text("Center Text",)),
);
}
}
I get This result. (Flutter 1.22.5)

How to hide the keyboard with onTap the screen?

While using the text fields in flutter,
how we can able to hide the keyboard after its use just by tapping on the screen.
We can use FocusNode
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
),
);
}
}
We can make use of FocusScope.of(context).unfocus(); to hide the keyboard. Wrap entire Scaffold with Gesture detector and on tap make use of FocusScope.of(context).unfocus(); to hide the keyboard on tap of any part of the screen.
Please refer below working code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _controller = new TextEditingController();
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScope.of(context).unfocus(); // To hide the keyboard
},
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: TextFormField(
controller: _controller,
decoration: new InputDecoration(labelText: 'Example Text'),
),
),
);
}
}

trying to make call from IOS

I'm trying to use url_launcher so that through a button it takes me to the dialer of my phone to make a call. In android it works perfectly but when I run it in IOS it does not work, it does nothing, I don't know if something is missing in the code, I appreciate your help
This is the code I am using:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final String _phoneNumber = '318654378';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RaisedButton(
child: Text('Call Number'),
onPressed: () {
if (Platform.isAndroid) {
// _callNumber();
launch('tel://$_phoneNumber');
} else if (Platform.isIOS) {
launch('tel://$_phoneNumber');
}
}),
),
);
}
}
Any idea what is going on