I can't use onGenerateRoute because there is always an error. I watched different tutorials but I can't find the problem. GenerateRoute behind the "Route>dynamic>" is always underlined red.
This is my "route_generator.dart" file:
import 'package:flutter/material.dart';
import 'package:rave/src/app.dart';
class RouteGenerator{
static Route<dynamic> generateRoute(RouteSettings settings){
}
}
and this is my "app.dart" file, the RouteGenerator behind "onGenerateRoute:" is also underlined red:
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:rave/src/Screens/init.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
theme: ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: const Color(0xff1f1f1f),
canvasColor: const Color(0xff1f1f1f),
),
home: InitScreen(),
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
Related
enter image description herei added the getx package to my pubspec.yaml file and import the 'get/get.dart' in main.dart but when i want to use getPages, i cant and it gives an error
I don't know what to try because I don't know much about getx package
You should use GetMaterialApp widget instead of MaterialApp since its the widget from get package
Example:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'My App',
theme: ThemeData(
scaffoldBackgroundColor: const Color(0xff262626),
brightness: Brightness.dark,
),
initialRoute: '/',
getPages: [
GetPage(name: '/', page: () => HomePage()),
],
);
}
}
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(),
},
)
I have declared primary color to Color(0xFF0C9869) to this which is kind of green color but the appbar is always blue until I change it in appbar widget why is my primary color not working. I am running this code in android studio.
main.dart
import 'package:flutter/material.dart';
import 'package:plant/components/home.dart';
import 'package:plant/constraint.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(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primaryColor: kPrimaryColor,
scaffoldBackgroundColor: kBackgroundColor,
textTheme: Theme.of(context).textTheme.apply(bodyColor: kTextColor),
),
home: Homescreen(),
);
}
}
constraint.dart
import 'package:flutter/material.dart';
const kPrimaryColor = Color(0xFF0C9869);
const kTextColor = Color(0xFF3C4046);
const kBackgroundColor = Color(0xFF9F8FD);
const double kDefaultPadding = 20.0;
home.dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class Homescreen extends StatelessWidget {
const Homescreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildAppBar(),
);
}
AppBar buildAppBar() {
return AppBar(
elevation: 0,
leading: IconButton(
onPressed: () {},
icon: SvgPicture.asset("assets/icons/menu.svg")
),
);
}
}
you will have to declare it in appBarTheme in ThemeData .
theme: ThemeData(
primaryColor: kPrimaryColor,
scaffoldBackgroundColor: kBackgroundColor,
textTheme: Theme.of(context).textTheme.apply(bodyColor: kTextColor),
appBarTheme: AppBarTheme(backgroundColor: kPrimaryColor),
),
Flutter when use riverpod in release mode application crash and when remove provider scope it is working. Widgets do not appear when the application is opened.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:grock/grock.dart';
import 'package:turesta/constant/constant.dart';
import 'package:turesta/view/normal/splash/splash.dart';
void main() {
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends ConsumerWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context, WidgetRef ref) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Turesta',
navigatorKey: Grock.navigationKey,
scaffoldMessengerKey: Grock.snackbarMessengerKey,
theme: ThemeData(
scaffoldBackgroundColor: Constant.scaffoldBgColor,
),
home: Splash(),
);
}
}
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)