import 'package:flutter/material.dart';标签:20.0,usernameController,const,textController,text,TextEditingController,5.15 From: https://www.cnblogs.com/kongxiangzeng/p/18246558
import '../Do/UserDao.dart';
class InsertColumn extends StatelessWidget {
InsertColumn({super.key});
// Create controllers
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _textController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('发帖'),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
TextFormField(
controller: _usernameController,
decoration: InputDecoration(
labelText: '发帖人',
),
),
const SizedBox(height: 20.0),
TextFormField(
controller: _textController,
decoration: InputDecoration(
labelText: '帖子内容',
),
),
const SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
// Get user input values
String username = _usernameController.text.trim();
String text = _textController.text.trim();
// Simple input validation, you can add more validation logic as needed
if (username.isNotEmpty && text.isNotEmpty) {
insertColumn(context, username, text);
} else {
// Prompt user to input complete information
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请输入完整的信息'),
),
);
}
},
child: const Text('发布'),
),
],
),
),
);
}
}