我将如何在此 GridView 中编辑/定位具体项目。此 Gridview 列出了每个容器中 2020 年 1 月的日子。我将如何更改特定日期的容器边界?示例...我想将第一行中第二项的边框更改为红色而不是黑色 (01-02-2020)
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Grid List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: GridView.count(
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this produces 2 rows.
crossAxisCount: 4,
// Generate 100 widgets that display their index in the List.
children: getDayInWeek(),
),
),
);
}
}
List<Widget> getDayInWeek() {
var list = <DateTime>[];
DateTime start = DateTime(2020, 01, 01);
final end = DateTime(2020, 01, 31);
while (start.isBefore(end)) {
list.add(start);
start = start.add(const Duration(days: 1));
}
return list.map((DateTime time) {
return Container(
margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.all(.0),
decoration: myBoxDecoration(),
child: Column(
children: <Widget>[
Text(
new DateFormat("MM-dd-yyyy").format(time),
style: TextStyle(fontSize: 15.0, backgroundColor: Colors.white),
textAlign: TextAlign.center,
),
],
),
);
}).toList();
}
BoxDecoration myBoxDecoration() {
return BoxDecoration(
border: Border.all(width: .1),
);
}