Fetch URL Param

 avatar
unknown
dart
3 years ago
1.2 kB
4
Indexable
import 'package:flutter/material.dart';

void main() {
  String? userIdValue = Uri
      .base.queryParameters["user_id"]; //get parameter with attribute "para1"
  runApp(MyApp(userId: userIdValue)); //pass to MyApp class
}

class MyApp extends StatefulWidget {
  String? userId;

  MyApp({
    this.userId,
  }); //constructor of MyApp class

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "ICE - Medical Reports",
      home: Scaffold(
          appBar: AppBar(
            title: Text("SCAN QR"),
            backgroundColor: Colors.redAccent,
          ),
          body: Container(
              padding: EdgeInsets.all(20),
              alignment: Alignment.center,
              child: Column(
                children: [
                  //display parameters and URL here
                  Text(widget.userId == null
                      ? "UserId is null"
                      : "User ID = " + widget.userId!),
                ],
              ))),
    );
  }
}

//http://localhost:52499/?user_id=5f92cbf10cf217478ba93561