syedmurtaza108 / chucker-flutter

An HTTP requests inspector inspired by Chucker Android
https://pub.dev/packages/chucker_flutter
MIT License
54 stars 32 forks source link

Why chucker not showing notification #22

Closed Ram8948 closed 1 year ago

Ram8948 commented 1 year ago

https://stackoverflow.com/questions/74714788/chucker-flutter-why-chucker-not-showing-notification

syedmurtaza108 commented 1 year ago

@Ram8948 The code shown in the question is incomplete. Please add complete code here (e.g. where exactly you are calling _dio.get('$_baseUrl$path');). Also plz mention chucker version and flutter version here.

Ram8948 commented 1 year ago

@syedmurtaza108 syedmurtaza108 Sir Here is my complete code with the chucker version and flutter version: chucker_flutter: ^1.3.6 Flutter version: 3.3.9

class UserSearch extends StatefulWidget { UserSearch({Key? key}) : super(key: key);

@override State createState() => _UserSearchState(); }

class _UserSearchState extends State { Dio? dio; bool isLoading = false; bool isSearching = false; UserModel? user; final _debouncer = Debouncer(milliseconds: 500); String? errorMessage;

late final _dio = Dio( BaseOptions( baseUrl: 'https://api.github.com/', sendTimeout: const Duration(seconds: 50).inMilliseconds, connectTimeout: const Duration(seconds: 50).inMilliseconds, receiveTimeout: const Duration(seconds: 50).inMilliseconds, ), );

@override void initState() { super.initState(); BaseOptions options = BaseOptions(baseUrl: 'https://api.github.com/'); dio = Dio(options); _dio.interceptors.add(ChuckerDioInterceptor()); }

Future getUser(String name) async { print('get çalıştı'); setState(() { isLoading = true; }); try { final response = await _dio?.get('users/$name'); _dio?.options.headers["user-agent"] = "request"; if (response?.statusCode == 200) { user = UserModel.fromJson(response?.data); print('data geldi'); print('data ${user?.name}'); } setState(() { isLoading = false; errorMessage = null; }); } on DioError catch (e) { setState(() { errorMessage = e.response?.statusMessage; isLoading = false; }); print('Error Message ${e.response?.statusMessage}'); print(e.response?.headers); print(e.response?.requestOptions); } }

@override Widget build(BuildContext context) { return Scaffold( appBar: isSearching ? AppBar( // The search area here backgroundColor: Colors.black, title: Container( width: double.infinity, height: 40, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Center( child: TextField( onChanged: (word) { if (word != '') { _debouncer.run(() => (getUser(word))); print('kelime $word'); } }, decoration: InputDecoration( prefixIcon: const Icon(Icons.search), suffixIcon: IconButton( icon: const Icon(Icons.clear), onPressed: () { setState(() { isSearching = false; isLoading = false; }); }, ), hintText: 'Search...', border: InputBorder.none), ), ), )) : AppBar( backgroundColor: Colors.black, title: const Text('Search User'), actions: [ IconButton( onPressed: () { setState(() { isSearching = true; }); }, icon: const Icon(Icons.search)) ]), body: isLoading == true ? Container( alignment: Alignment.center, color: Colors.black, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: 300, height: 300, child: LiquidCircularProgressIndicator( value: 0.7, center: Text( 'Loading..', style: TextStyle(fontSize: 20, color: Colors.white), ), backgroundColor: Colors.white, ), ) ], ), ) : errorMessage != null || user?.name == null ? SorryWidget() : UserPage( user: user, )); } }

syedmurtaza108 commented 1 year ago

@Ram8948 Have you added NavigatorObserver in your MaterialApp widget, commonly placed in main.dart?

MaterialApp(
      ...,
      navigatorObservers: [ChuckerFlutter.navigatorObserver],
Ram8948 commented 1 year ago

@syedmurtaza108 Sir i have added this one also

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', navigatorObservers: [ChuckerFlutter.navigatorObserver], debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), onGenerateRoute: Routes.generateRoute, home: UserSearch()); } }

Ram8948 commented 1 year ago

Hii @syedmurtaza108 Sir,

it's working fine actually the notification box is hiding below the keyboard. I have checked on the web and mobile also.

syedmurtaza108 commented 1 year ago

@Ram8948 Oh okay. Thanks for letting me know.