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(),
);
}
}
Related
This is my main.dar and I got problems:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:pomodoroTimer/1.app_bar_pomodoro/profile/colors.dart';
import 'apilar_codigo/stacked_all.dart';
void main() async {
// initialize hive
await Hive.initFlutter();
// open a box
await Hive.openBox("Habit_Database");
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
textTheme: GoogleFonts.nunitoTextTheme(Theme.of(context).textTheme),
useMaterial3: true,
colorScheme:
ColorScheme.light(primary: ColorsToAPP.selectText)),
home: const StackePages(),
);
}
}
Is there a piece of code that I'm missing out? because I can't run the app
Thanks for any help you can provide
How can I run main.dart without problems?
You are missing the code that will actually run the app:
void main() async {
...
runApp(MyApp());
}
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 have made a new file in my views folder but whenever I turn on the emulator and run the code, it just says "Hello World".
Is there a way I can set the starting point of the project to be on this new file? Because it only seems to turn on the main.dart file.
This is the code that is in the views file called home_page.dart . It is supposed to just say "Hi" 10 times.
import 'package:flutter/material.dart';
import '../models/post.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<Post>? posts;
var isLoaded = false;
#override
void initState() {
super.initState();
//fetch data from API
getData();
}
getData() async {
// posts = await
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Posts'),
),
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Container(
child: Text('Hi'),
);
},
)
);
}
}
in flutter the main.dart file is the first file
import 'package:flutter/material.dart';
import 'package:get/get_navigation/src/root/get_material_app.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,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),//add your home page here
);
}
}
I previously asked a question regarding flutter and null and was able to find a more recent notes app. The thing is whenever I run it I get the [core/no app] error. and once I fix those errors by adding core to the dependencies and adding those two lines on main.dart. I get even more errors.
import 'package:flutter/material.dart';
import 'package:dailymi2/pages/homepage.dart';
import 'package:dailymi2/values/theme.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database/firebase_database.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: myTheme(context),
title: 'dailymi',
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
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,
);
}
}