the thing I will like to ask about is that I want to pass the data in the barcode to a new page after scanning. Is there anyway can I do it?

Hope anyone can solve my problem <3

Had been doing this for my intern for 4 days and I have no clue at all. Hope can solve it as fast as possible

Below is my code:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:meditation_app/widgets/category_card.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key key}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  String _scanBarcode = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  Future<void> scanBarcodeNormal() async {
    String barcodeScanRes ;
      try {
        barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
            '#ff6666', 'Cancel', true, ScanMode.BARCODE);
        print(barcodeScanRes);
      } on PlatformException {
        barcodeScanRes = 'Failed to get platform version.';
      }
      if (!mounted) return;
      setState(() {
        _scanBarcode = barcodeScanRes; //Here is the thing I will like to pass to another page
      });
    }

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text('EzyMerchant'),
        actions: <Widget>[
          IconButton(
            icon: SvgPicture.asset("assets/icons/setting.svg",color: Colors.white,),
            onPressed: () {
              Navigator.pushNamed(context, '/setting');
            },
          ),
        ],
      ),
      body: Stack(
        children: <Widget>[
          SafeArea(
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20, vertical:20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    "Good Morning \nAdmin",
                    style: Theme.of(context)
                        .textTheme
                        .headline4
                        .copyWith(fontWeight: FontWeight.w900),
                  ),
                  SizedBox(height: 50),
                  Expanded(
                    child: Container(
                      child: GridView.count(
                        crossAxisCount: 2,
                        childAspectRatio: .85,
                        crossAxisSpacing: 20,
                        mainAxisSpacing: 20,
                        children: <Widget>[
                          Container(
                            child: CategoryCard(
                              title: "Add",
                              svgSrc: ("assets/icons/Hamburger.svg"),
                              press: () => scanBarcodeNormal(), //Here is the scan function 
                            ),
                          ),
                          CategoryCard(
                            title: "Redeem",
                            svgSrc: "assets/icons/Excrecises.svg",
                            press: () {},
                          ),
                          CategoryCard(
                            title: "Wallet",
                            svgSrc: "assets/icons/Meditation.svg",
                            press: () {},
                          ),
                          CategoryCard(
                            title: "Voucher",
                            svgSrc: "assets/icons/yoga.svg",
                            press: () {},
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}


Solution 1: khunt arpit

You can use arguments property in Navigator.pushNamed like

Navigator.pushNamed(context, '/setting',arguments: _scanBarcode);