我在我的 flutter 项目中使用了 razorpayWeb 插件,但我很困惑如何在 razorpay 选项中获取动态数据

i used razorpayWeb plugin in my flutter project but i am confused how to get dynamic data in razorpay options

import 'package:flutter/material.dart';
import 'package:futurek/homepage.dart';

void main() {
  runApp(const MyApp());
}

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',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}


***nav bar**

import 'package:flutter/material.dart';

class NavBar extends StatelessWidget {
  const NavBar({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer();
  }
}



*homepage*

import 'package:futurek/shoe_page.dart'; // ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, unused_element

import 'package:flutter/material.dart';
import 'package:futurek/navbar.dart';

class CardItem {
  final String urlImage;
  final String title;
  final String subtitle;

  const CardItem({
    required this.urlImage,
    required this.title,
    required this.subtitle,
  });
}

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  List<CardItem> items = [
    CardItem(
      urlImage:
          'https://images.pexels.com/photos/2529147/pexels-photo-2529147.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
      title: 'Nike Free Run',
      subtitle: '10',
    ),
    CardItem(
      urlImage:
          'https://underarmour.scene7.com/is/image/Underarmour/3024250-404_DEFAULT?rp=standard-30pad|gridTileDesktop&scl=1&fmt=jpg&qlt=50&resMode=sharp2&cache=on,on&bgc=F0F0F0&wid=512&hei=640&size=472,600',
      title: 'Adidad free run',
      subtitle: '50',
    ),
    CardItem(
      urlImage:
          'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRpozlaZ5vCRX6qz1ISfI7a2swqpFXvivy47jR1POAai3qom_f4KIMOB-gQoXdnzeLOUXk&usqp=CAU',
      title: 'Reebok',
      subtitle: '70',
    ),
    CardItem(
      urlImage:
          'https://image.shutterstock.com/image-photo/pair-pink-sport-shoes-on-260nw-228691018.jpg',
      title: 'Puma',
      subtitle: '89',
    ),
    CardItem(
      urlImage:
          'https://images.creator-prod.zmags.com/image/upload/q_auto,dpr_2.625,f_auto/c_scale,w_300/621cf9017826497cf6ceb463.jpeg',
      title: 'Jordan',
      subtitle: '97',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: NavBar(),
      appBar: AppBar(),
      body: SingleChildScrollView(
        child: Column(
          children: [
            SizedBox(height: 3),
            Container(
              child: Align(
                alignment: Alignment.topLeft,
                child: Text(
                  'Category',
                  style: TextStyle(
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 300,
              child: ListView.separated(
                shrinkWrap: true,
                primary: false,
                padding: EdgeInsets.all(5),
                scrollDirection: Axis.horizontal,
                itemCount: 5,
                separatorBuilder: (context, _) => SizedBox(
                  width: 12,
                ),
                itemBuilder: (context, index) =>
                    buildCard(item: items[index], context: context),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // ignore: dead_code
  Widget buildCard({
    required CardItem item,
    required BuildContext context,
  }) =>
      Expanded(
        child: Container(
          height: 100,
          width: 200,
          child: Column(
            children: [
              Expanded(
                child: AspectRatio(
                  aspectRatio: 4 / 3,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(40),
                    child: Material(
                      child: Ink.image(
                        image: NetworkImage(item.urlImage),
                        fit: BoxFit.cover,
                        child: InkWell(
                          onTap: () => Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => ShoePage(
                                        item: item,
                                      ))),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 4,
              ),
              Text(
                item.title,
                style: TextStyle(
                    fontSize: 24,
                    fontWeight: FontWeight.w300,
                    color: Colors.black),
              ),
              Text(
                item.subtitle,
                style: TextStyle(fontSize: 20, color: Colors.black),
              )
            ],
          ),
        ),
      );
}


*shoepage*

import 'dart:ui';
import 'dart:developer';
import 'package:futurek/homepage.dart';
import 'package:razorpay_web/razorpay_web.dart';
import 'package:futurek/razorpaypopup.dart';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class ShoePage extends StatefulWidget {
  final CardItem item;

  const ShoePage({
    Key? key,
    required this.item,
  }) : super(key: key);

  @override
  State<ShoePage> createState() => _ShoePageState();
}

class _ShoePageState extends State<ShoePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.item.title),
      ),
      body: SafeArea(
        child: LayoutBuilder(builder: (context, constraints) {
          if (constraints.maxWidth < 768) {
            return Column(
              children: [
                AspectRatio(
                  aspectRatio: 4 / 3,
                  child: Image.network(
                    widget.item.urlImage,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  widget.item.title,
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w200,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Builder(
                    builder: (context) => Center(
                        child: ElevatedButton(
                            child: Text("BuyNow"),
                            onPressed: () => Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Payments()),
                                ))))
              ],
            );
          } else {
            return Row(
              children: [
                AspectRatio(
                  aspectRatio: 4 / 3,
                  child: Image.network(
                    widget.item.urlImage,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  widget.item.title,
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w200,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Builder(
                    builder: (context) => Center(
                        child: ElevatedButton(
                            child: Text("Buy Now"),
                            onPressed: () => Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Payments()),
                                ))))
              ],
            );
          }
        }),
      ),
    );
  }
}


*razorpaypopup*

import 'dart:ui';
import 'dart:developer';
import 'package:futurek/homepage.dart';
import 'package:razorpay_web/razorpay_web.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:futurek/shoe_page.dart'; // ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, unused_element

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

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

class _PaymentsState extends State<Payments> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: RazorpayWeb(
          rzpKey: "rzp_test_DNaSxot4oJHykG", // Enter Your Razorpay Key Here
          options: RzpOptions(
            amount: 1000,
            name: '',
            description: "Test Payment",
            image: "https://i.imgur.com/3g7nmJC.png",
            prefill: const PrefillData(
              name: "Razorpay",
              email: "rzp@gmail.com",
              contact: "9876543210",
            ),
            colorhex: "#FF0000",
          ),
          onPaymentSuccess: (String paymentId) {
            print("Payment Success");
            log(paymentId);
          },
          onPaymentError: (String error) {
            print("Payment Error");
          },
        ),
      ),
    );
  }
}

大家好,我在我的 flutter 项目中使用了 razorpayWeb 插件,但我很困惑如何在 razorpay 选项中获取动态数据,以便 razorpay 可以根据产品自动捕获数据,这是我的存储库 link = github.com/AbhiEntrepreneur/razorpayweb我希望我能得到你们的积极回应

试试这个

import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:razorpay_web/razorpay_web.dart';

void main() {
  runApp(HomePage());
}

class NavBar extends StatelessWidget {
  const NavBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer();
  }
}

class CardItem {
  final String urlImage;
  final String title;
  final String subtitle;

  const CardItem({
    required this.urlImage,
    required this.title,
    required this.subtitle,
  });
}

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  List<CardItem> items = [
    CardItem(
      urlImage:
          'https://images.pexels.com/photos/2529147/pexels-photo-2529147.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
      title: 'Nike Free Run',
      subtitle: '10',
    ),
    CardItem(
      urlImage:
          'https://underarmour.scene7.com/is/image/Underarmour/3024250-404_DEFAULT?rp=standard-30pad|gridTileDesktop&scl=1&fmt=jpg&qlt=50&resMode=sharp2&cache=on,on&bgc=F0F0F0&wid=512&hei=640&size=472,600',
      title: 'Adidad free run',
      subtitle: '50',
    ),
    CardItem(
      urlImage:
          'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRpozlaZ5vCRX6qz1ISfI7a2swqpFXvivy47jR1POAai3qom_f4KIMOB-gQoXdnzeLOUXk&usqp=CAU',
      title: 'Reebok',
      subtitle: '70',
    ),
    CardItem(
      urlImage:
          'https://image.shutterstock.com/image-photo/pair-pink-sport-shoes-on-260nw-228691018.jpg',
      title: 'Puma',
      subtitle: '89',
    ),
    CardItem(
      urlImage:
          'https://images.creator-prod.zmags.com/image/upload/q_auto,dpr_2.625,f_auto/c_scale,w_300/621cf9017826497cf6ceb463.jpeg',
      title: 'Jordan',
      subtitle: '97',
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        drawer: NavBar(),
        appBar: AppBar(),
        body: SingleChildScrollView(
          child: Column(
            children: [
              SizedBox(height: 3),
              Container(
                child: Align(
                  alignment: Alignment.topLeft,
                  child: Text(
                    'Category',
                    style: TextStyle(
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 0),
              Container(
                height: 300,
                child: ListView.separated(
                  shrinkWrap: true,
                  primary: false,
                  padding: EdgeInsets.all(5),
                  scrollDirection: Axis.horizontal,
                  itemCount: 5,
                  separatorBuilder: (context, _) => SizedBox(
                    width: 12,
                  ),
                  itemBuilder: (context, index) =>
                      buildCard(item: items[index], context: context),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  // ignore: dead_code
  Widget buildCard({
    required CardItem item,
    required BuildContext context,
  }) =>
      Expanded(
        child: Container(
          height: 100,
          width: 200,
          child: Column(
            children: [
              Expanded(
                child: AspectRatio(
                  aspectRatio: 4 / 3,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(40),
                    child: Material(
                      child: Ink.image(
                        image: NetworkImage(item.urlImage),
                        fit: BoxFit.cover,
                        child: InkWell(
                          onTap: () => Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => ShoePage(
                                        item: item,
                                      ))),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 4,
              ),
              Text(
                item.title,
                style: TextStyle(
                    fontSize: 24,
                    fontWeight: FontWeight.w300,
                    color: Colors.black),
              ),
              Text(
                item.subtitle,
                style: TextStyle(fontSize: 20, color: Colors.black),
              )
            ],
          ),
        ),
      );
}

class ShoePage extends StatefulWidget {
  final CardItem item;

  const ShoePage({
    Key? key,
    required this.item,
  }) : super(key: key);

  @override
  State<ShoePage> createState() => _ShoePageState();
}

class _ShoePageState extends State<ShoePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.item.title),
      ),
      body: SafeArea(
        child: LayoutBuilder(builder: (context, constraints) {
          if (constraints.maxWidth < 768) {
            return Column(
              children: [
                AspectRatio(
                  aspectRatio: 4 / 3,
                  child: Image.network(
                    widget.item.urlImage,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  widget.item.title,
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w200,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Builder(
                    builder: (context) => Center(
                        child: ElevatedButton(
                            child: Text("BuyNow"),
                            onPressed: () => Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Payments(
                                            title: widget.item.title,
                                            urlImage: widget.item.urlImage,
                                          )),
                                ))))
              ],
            );
          } else {
            return Row(
              children: [
                AspectRatio(
                  aspectRatio: 4 / 3,
                  child: Image.network(
                    widget.item.urlImage,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Text(
                  widget.item.title,
                  style: TextStyle(
                    fontSize: 32,
                    fontWeight: FontWeight.w200,
                  ),
                ),
                SizedBox(
                  height: 8,
                ),
                Builder(
                    builder: (context) => Center(
                        child: ElevatedButton(
                            child: Text("Buy Now"),
                            onPressed: () => Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => Payments(
                                            title: widget.item.title,
                                            urlImage: widget.item.urlImage,
                                          )),
                                ))))
              ],
            );
          }
        }),
      ),
    );
  }
}

class Payments extends StatefulWidget {
  Payments({Key? key, required this.title, required this.urlImage})
      : super(key: key);
  String title;
  String urlImage;
  @override
  _PaymentsState createState() => _PaymentsState();
}

class _PaymentsState extends State<Payments> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: RazorpayWeb(
          rzpKey: "rzp_test_DNaSxot4oJHykG", // Enter Your Razorpay Key Here
          options: RzpOptions(
            amount: 1000,
            name: '',
            description: widget.title,
            image: widget.urlImage,
            prefill: const PrefillData(
              name: "Razorpay",
              email: "rzp@gmail.com",
              contact: "9876543210",
            ),
            colorhex: "#FF0000",
          ),
          onPaymentSuccess: (String paymentId) {
            print("Payment Success");
            log(paymentId);
          },
          onPaymentError: (String error) {
            print("Payment Error");
          },
        ),
      ),
    );
  }
}