dd(String descriptin) değer nasıl atabilirim?
buildTextField girilen text alanını add() fonksiyonuna eklemem gerekli
onPressed: () => add(), neler yazmam gerekli?
import 'package:barcode_widget/barcode_widget.dart';
import 'package:flutter/material.dart';
import 'package:aryee/main.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'dart:io';
class QRCreatePage extends StatefulWidget {
@override
_QRCreatePageState createState() => _QRCreatePageState();
}
class _QRCreatePageState extends State<QRCreatePage> {
final controller = TextEditingController();
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text("MyApp.title"),
),
body: Center(
child: SingleChildScrollView(
padding: EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BarcodeWidget(
barcode: Barcode.qrCode(),
color: Colors.white,
data: controller.text ?? 'Hello world',
width: 200,
height: 200,
),
SizedBox(height: 40),
Row(
children: [
Expanded(child: buildTextField(context)),
const SizedBox(width: 12),
FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
child: Icon(Icons.done, size: 30),
// onPressed: () => setState(() {}),
onPressed: () => add(),
)
],
),
],
),
),
),
);
Widget buildTextField(BuildContext context) => TextField(
controller: controller,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20,
),
decoration: InputDecoration(
hintText: 'Enter the data',
hintStyle: TextStyle(color: Colors.grey),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
),
),
),
);
void add(String description) async {
String apiUrl = "https://localhost:44382/api/QRCode/Add";
var dio = Dio();
var params = {
"description": description,
"path": "dsfdsf",
};
Response response = await dio.post(
apiUrl,
options: Options(headers: {
HttpHeaders.contentTypeHeader: "application/json",
}),
data: jsonEncode(params),
);
// final json =
// jsonEncode({"description": "test açıklama", "path": "test yol"});
// http.Response response = await http.put(Uri.parse(apiUrl), body: json);
// var jsonResponse = jsonDecode(response.body);
// print(jsonResponse);
}
}