import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme!.primary,
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_showModalBottomSheet(context); // Pass context here
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
void _showModalBottomSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Modal Bottom Sheet',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
aboutnoteorfolder(
context,
arrowoperation: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return V();
},
));
},
);
},
child: Text('Next'),
),
],
),
),
);
},
);
}
void aboutnoteorfolder(
BuildContext context, {
required Function() arrowoperation,
}) {
final AnimationController controller = AnimationController(
vsync: Navigator.of(context),
reverseDuration: Duration(milliseconds: 250),
duration: Duration(milliseconds: 700),
);
showModalBottomSheet(
elevation: 0,
transitionAnimationController: controller,
useSafeArea: true,
isScrollControlled: true,
backgroundColor: Colors.transparent,
barrierColor: const Color.fromARGB(90, 0, 0, 0),
context: context,
builder: (context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.width * 0.02),
child: GestureDetector(
onTap:arrowoperation,
child: Container(
width: MediaQuery.of(context).size.width * .955,
height: MediaQuery.of(context).size.width * .65,
decoration: BoxDecoration(
color: Color.fromARGB(255, 0, 128, 255),
border: Border.all(
width: MediaQuery.of(context).size.width * 0.0030,
color: Color.fromARGB(120, 255, 255, 255),
),
borderRadius: BorderRadius.all(Radius.circular(
MediaQuery.of(context).size.width * 0.11,
)),
),
child: Center(
child: Text(
"Navigate"
),
),
),
));
});
}
class V extends StatelessWidget {
const V({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Scaffold();
}
}
**
My issue is that when the plus icon is pressed, a bottom sheet appears. Upon pressing the "Next" button in that bottom sheet, another blue sheet appears. When I press this blue sheet, I want to navigate to page V. However, I’m encountering the following error:
════════ Exception caught by gesture ═══════════════════════════════════════════
Null check operator used on a null value
**
2
Answers
replace the code,
just set a diferent names for your buidlContext
in this case i’ve renamed the showModalBottomSheet context to ctx2
take a look at :https://api.flutter.dev/flutter/widgets/BuildContext-class.html
The root cause for this issue is:
Solution: you should use a different context instead of the bottom sheet context:
builder: (_) {...}