我想做一个和这个类似的设计
其中用户可以创建笔记,然后该笔记将被显示到屏幕中,并且保存该笔记的窗口小部件必须占用屏幕的空间(不是屏幕的全部空间,而是屏幕的一部分空间)。
下面是我设法做到的,但问题是有两个列表,一个用于第一列,另一个用于第二列,当添加注解时,它只能添加到其中一列。
下面是我的代码:
import 'package:flutter/material.dart';
void main() => runApp(HomePage());
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.menu),
Text('Home'),
Icon(Icons.search),
],
),
Row(
children: [
Padding(
padding: const EdgeInsets.only(top: 25.0),
child: Container(
height: 500,
child: const Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
NoteBlock(title: 'To Do List', content: 'fjskfjsk'),
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
],
),
Column(
children: [
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
NoteBlock(title: 'Travelling', content: 'fjskfjsk'),
],
)
],
),
),
),
],
)
],
),
)),
));
}
}
class NoteBlock extends StatelessWidget {
final String title;
final String content;
const NoteBlock({
super.key,
required this.title,
required this.content,
});
@override
Widget build(BuildContext context) {
return Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
color: const Color(0xFFF7F7F7),
height: 100,
width: MediaQuery.of(context).size.width / 2 - 30,
child: Padding(
padding: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(fontSize: 20),
),
SizedBox(height: 20),
Text(content),
],
),
),
),
),
);
}
}
2条答案
按热度按时间p4tfgftt1#
这就是我的想法
当添加注解(删除、更改等)时,请确保更改
notes
变量,并调用NotePage小部件的setState!希望它能有所帮助rt4zxlrg2#
我发现了一个很好的方法来实现它,使用一个名为flutter_staggered_grid_view的第三方软件包,下面是代码:
notes
列表包含NoteBook
小部件列表。