Commit 33c7586e authored by Administrator's avatar Administrator

system generated tagGroups can only be inspected, not edited

parent ed3ba5c9
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/models/athlete.dart';
......@@ -20,10 +21,11 @@ class TagGroup extends ChangeNotifier {
TagGroup.by(
{@required Athlete athlete,
@required String name,
@required bool system}) {
@required bool system,
@required int color}) {
db = DbTagGroup()
..athletesId = athlete.db.id
..color = Colors.lightGreen.value
..color = color
..system = system
..name = name;
}
......@@ -39,6 +41,7 @@ class TagGroup extends ChangeNotifier {
name: "Auto Heart Rate Zones",
athlete: athlete,
system: true,
color: MyColor.grapeFruit.value,
);
await autoHeartRateZones.db.save();
......@@ -46,6 +49,7 @@ class TagGroup extends ChangeNotifier {
name: "Auto Power Zones",
athlete: athlete,
system: true,
color: MyColor.bitterSweet.value,
);
await autoPowerZonesTagGroup.db.save();
}
......
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
class ShowTagGroupScreen extends StatefulWidget {
final TagGroup tagGroup;
const ShowTagGroupScreen({Key key, this.tagGroup}) : super(key: key);
@override
_AddTagGroupScreenState createState() => _AddTagGroupScreenState();
}
class _AddTagGroupScreenState extends State<ShowTagGroupScreen> {
List<Tag> tags = [];
int offset = 0;
int rows;
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.settings,
title: Text('Show Tag Group'),
),
body: ListView(
padding: EdgeInsets.only(left: 20, right: 20),
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: "Name"),
initialValue: widget.tagGroup.db.name,
readOnly: true,
),
SizedBox(height: 20),
Row(children: [
Text("Color"),
Spacer(),
CircleAvatar(
backgroundColor: Color(widget.tagGroup.db.color),
radius: 20.0,
),
Spacer(),
]),
SizedBox(height: 20),
DataTable(
headingRowHeight: kMinInteractiveDimension * 0.80,
dataRowHeight: kMinInteractiveDimension * 0.75,
columnSpacing: 20,
horizontalMargin: 10,
columns: <DataColumn>[
DataColumn(label: Text("Tag")),
DataColumn(label: Text("Color")),
],
rows: tags.map((Tag tag) {
return DataRow(
key: Key(tag.db.id.toString()),
cells: [
DataCell(Text(tag.db.name)),
DataCell(CircleColor(
circleSize: 20,
elevation: 0,
color: Color(tag.db.color),
)),
],
);
}).toList(),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(width: 5),
MyButton.cancel(onPressed: () => Navigator.of(context).pop()),
],
),
],
),
);
}
getData() async {
tags = await widget.tagGroup.tags;
setState(() {});
}
}
import 'package:encrateia/screens/add_tag_group_screen.dart';
import 'package:encrateia/screens/show_tag_group_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
......@@ -62,14 +63,16 @@ class _AthleteTagGroupWidgetState extends State<AthleteTagGroupWidget> {
color: Color(tagGroup.db.color),
)),
DataCell(
MyIcon.edit,
tagGroup.db.system ? MyIcon.show : MyIcon.edit,
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTagGroupScreen(
tagGroup: tagGroup,
),
builder: (context) {
if (tagGroup.db.system)
return ShowTagGroupScreen(tagGroup:tagGroup); else
return AddTagGroupScreen(tagGroup: tagGroup);
},
),
);
getData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment