How can I navigate between 2 classes, one of them requires passing data? in flutter

you can use constructor but in this case, whenever you use this class, you have to provide value, also you can make class value nullable and check it on build time. Another way is passing data by Route. for more navigate-with-arguments Here are is example: Passing data using ModalRoute Navigator.of(context).push( MaterialPageRoute( builder: (context) => WidgetA(), … Read more

Flutter: Keep BottomNavigationBar When Push to New Screen with Navigator

Screenshot: Starting point: void main() => runApp(MaterialApp(home: HomePage())); HomePage [BottomNavigationBar + Page1] class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( bottomNavigationBar: BottomNavigationBar( backgroundColor: Colors.orange, items: [ BottomNavigationBarItem(icon: Icon(Icons.call), label: ‘Call’), BottomNavigationBarItem(icon: Icon(Icons.message), label: ‘Message’), ], ), body: Navigator( onGenerateRoute: (settings) { Widget page = Page1(); if (settings.name == ‘page2’) page = … Read more

Style BottomNavigationBar in Flutter

There is no option to specify the background color of BottomNavigationBar but to change the canvasColor. One way you can achieve it without messing up the whole app would be by wrapping BottomNavigationBar in a Theme with desired canvasColor. Example: bottomNavigationBar: new Theme( data: Theme.of(context).copyWith( // sets the background color of the `BottomNavigationBar` canvasColor: Colors.green, … Read more

Flutter how to draw semicircle (half circle)

Create a StatelessWidget say MyArc which accepts a diameter. import ‘dart:math’ as math; class MyArc extends StatelessWidget { final double diameter; const MyArc({Key key, this.diameter = 200}) : super(key: key); @override Widget build(BuildContext context) { return CustomPaint( painter: MyPainter(), size: Size(diameter, diameter), ); } } // This is the Painter class class MyPainter extends CustomPainter … Read more

Flutter API Fetch and Sending Data from One screen to another screen

You should try to declare constructor the first page accept the id and push this id to second page or screen like this below code is first page Navigator.push( context, MaterialPageRoute( builder: (context) => ABC.withId( id, ), ), ) the create constructor inside second page screen class ABC extends StatefulWidget { @override _ABCState createState() => … Read more

How to implement a Custom dialog box in flutter?

Use Dialog class which is a parent class to AlertDialog class in Flutter. Dialog widget has a argument , “shape” which you can use to shape the Edges of the Dialog box. Here is a code sample: Dialog errorDialog = Dialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), //this right here child: Container( height: 300.0, width: 300.0, child: Column( … Read more

How to detect swipe in flutter

Use GestureDetector.onPanUpdate: GestureDetector( onPanUpdate: (details) { // Swiping in right direction. if (details.delta.dx > 0) {} // Swiping in left direction. if (details.delta.dx < 0) {} }, child: YourWidget(), ) To cover all the area (passing the parent constraints to the widget), you can include SizedBox.expand. SizedBox.expand( child: GestureDetector( onPanUpdate: (details) { // Swiping in … Read more