pikapika/lib/basic/config/ListLayout.dart

58 lines
1.4 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 列表页的布局
import 'package:event/event.dart';
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
enum ListLayout {
INFO_CARD,
ONLY_IMAGE,
COVER_AND_TITLE,
}
2021-11-04 05:56:25 +00:00
const Map<String, ListLayout> _listLayoutMap = {
'详情': ListLayout.INFO_CARD,
'封面': ListLayout.ONLY_IMAGE,
'封面+标题': ListLayout.COVER_AND_TITLE,
};
const _propertyName = "listLayout";
2021-09-29 23:57:09 +00:00
late ListLayout currentLayout;
2021-11-04 05:56:25 +00:00
var listLayoutEvent = Event<EventArgs>();
2021-09-29 23:57:09 +00:00
Future<void> initListLayout() async {
currentLayout = _listLayoutFromString(await method.loadProperty(
_propertyName,
ListLayout.INFO_CARD.toString(),
));
}
ListLayout _listLayoutFromString(String layoutString) {
for (var value in ListLayout.values) {
if (layoutString == value.toString()) {
return value;
}
}
return ListLayout.INFO_CARD;
}
2021-11-04 05:56:25 +00:00
void _chooseListLayout(BuildContext context) async {
2021-09-29 23:57:09 +00:00
ListLayout? layout = await chooseMapDialog(context, _listLayoutMap, '请选择布局');
if (layout != null) {
await method.saveProperty(_propertyName, layout.toString());
currentLayout = layout;
listLayoutEvent.broadcast();
}
}
2021-11-04 05:56:25 +00:00
IconButton chooseLayoutActionButton(BuildContext context) => IconButton(
2021-09-29 23:57:09 +00:00
onPressed: () {
2021-11-04 05:56:25 +00:00
_chooseListLayout(context);
2021-09-29 23:57:09 +00:00
},
2022-03-25 14:57:30 +00:00
icon: const Icon(Icons.view_quilt),
2021-09-29 23:57:09 +00:00
);
2023-02-16 08:14:29 +00:00
const chooseListLayout = _chooseListLayout;