When I click on the text field to start writing, the text field appears and disappears immediately. I tried to remove the ScreenUtil widgets and it's worked but I also tried to replace the GoRouter with on generate route by removing the ScreenUtils widget and it also worked. but I need this ScreenUtils widget in order to implement responsive app
Thi is my code
main.dart:
import 'package:bloc/bloc.dart';
import 'package:elcampione/presentation/app.dart';
import 'package:elcampione/presentation/bloc_observer.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'data/repositories/repositories.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Prevent screen from rotating
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
Bloc.observer = AppBlocObserver();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
final authenticationRepository = AuthenticationRepository();
await authenticationRepository.user.first;
runApp(App(authenticationRepository: authenticationRepository));
}
app.dart:
import 'package:elcampione/blocs/auth/auth_bloc.dart';
import 'package:elcampione/presentation/themes/theme.dart';
import 'package:elcampione/routes/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../data/repositories/repositories.dart';
class App extends StatelessWidget {
const App({
super.key,
required AuthenticationRepository authenticationRepository,
}) : _authenticationRepository = authenticationRepository;
final AuthenticationRepository _authenticationRepository;
@override
Widget build(BuildContext context) {
return RepositoryProvider<AuthenticationRepository>(
create: (context) => _authenticationRepository,
child: BlocProvider(
create: (_) => AuthBloc(
authenticationRepository: _authenticationRepository,
),
child: const AppView(),
),
);
}
}
class AppView extends StatelessWidget {
const AppView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final state = context.select((AuthBloc bloc) => bloc.state.status);
final isAuthenticated = state == AuthStatus.authenticated;
return ScreenUtilInit(
builder: (context, child) => MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
darkTheme: ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
title: 'El Campione',
locale: const Locale('en'),
routerConfig: AppRouter.router(isAuthenticated),
),
designSize: const Size(390, 844),
);
}
}
app_route_config.dart:
import 'package:elcampione/presentation/screens/screens.dart';
import 'package:elcampione/routes/app_route_constants.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class AppRouter {
static GoRouter router(bool isAuthenticated) {
GoRouter routes = GoRouter(
initialLocation: isAuthenticated ? '/home' : '/signin',
routes: [
GoRoute(
name: AppRoutesConstants.home,
path: '/home',
builder: (context, state) => const HomeScreen(),
),
GoRoute(
name: AppRoutesConstants.signIn,
path: '/signin',
builder: (context, state) => const SignInScreen(),
),
GoRoute(
name: AppRoutesConstants.signUp,
path: '/signup',
builder: (context, state) => const SignUpScreen(),
)
],
redirect: (context, state) => !isAuthenticated ? '/signin' : null,
);
return routes;
}
}