|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:auto_size_text/auto_size_text.dart'; |
| 5 | +import 'package:flutter_colorpicker/flutter_colorpicker.dart'; |
| 6 | +import 'package:flutter_rentnerend/widgets/color_picker.dart'; |
| 7 | + |
| 8 | +import 'md.dart'; |
| 9 | +import 'ws_client.dart'; |
| 10 | +import 'lib.dart' as lib; |
| 11 | + |
| 12 | + |
| 13 | +class TeamRow extends StatefulWidget { |
| 14 | + final String? defaultName; |
| 15 | + final bool initialShowPlayers; |
| 16 | + final Function(String) onNameChanged; |
| 17 | + final Function(Color) onColorChanged; |
| 18 | + |
| 19 | + const TeamRow({ |
| 20 | + super.key, |
| 21 | + this.defaultName, |
| 22 | + required this.initialShowPlayers, |
| 23 | + required this.onNameChanged, |
| 24 | + required this.onColorChanged, |
| 25 | + }); |
| 26 | + |
| 27 | + @override |
| 28 | + State<TeamRow> createState() => _TeamRowState(); |
| 29 | +} |
| 30 | + |
| 31 | +class _TeamRowState extends State<TeamRow> { |
| 32 | + late TextEditingController _controller; |
| 33 | + bool _showPlayers = false; |
| 34 | + |
| 35 | + @override |
| 36 | + void initState() { |
| 37 | + super.initState(); |
| 38 | + _controller = TextEditingController(text: widget.defaultName); |
| 39 | + } |
| 40 | + |
| 41 | + @override |
| 42 | + void dispose() { |
| 43 | + _controller.dispose(); |
| 44 | + super.dispose(); |
| 45 | + } |
| 46 | + |
| 47 | + @override |
| 48 | + Widget build(BuildContext context) { |
| 49 | + return Column(children: [ |
| 50 | + Row(children: [ |
| 51 | + Expanded(flex: 5, child: lib.ToggleIconButton( |
| 52 | + value: widget.initialShowPlayers, |
| 53 | + onChanged: (v) => setState(() => _showPlayers = v), |
| 54 | + )), |
| 55 | + Expanded(flex: 80, child: Autocomplete<String>( |
| 56 | + optionsBuilder: (TextEditingValue textEditingValue) { |
| 57 | + const List<String> opts = ["TEAM A"]; |
| 58 | + if (textEditingValue.text == '') |
| 59 | + return const Iterable<String>.empty(); |
| 60 | + return opts.where((String opt) { |
| 61 | + return opt.contains(textEditingValue.text); |
| 62 | + }); |
| 63 | + }, |
| 64 | + onSelected: (String selection) { |
| 65 | + widget.onNameChanged(selection); |
| 66 | + }, |
| 67 | + fieldViewBuilder: (context, controller, focusNode, onFieldSubmitted) { |
| 68 | + return TextField( |
| 69 | + controller: controller, |
| 70 | + focusNode: focusNode, |
| 71 | + textInputAction: TextInputAction.next, |
| 72 | + onSubmitted: (String value) => widget.onNameChanged(value), |
| 73 | + decoration: const InputDecoration( |
| 74 | + border: OutlineInputBorder(), |
| 75 | + hintText: "Team Name", |
| 76 | + //suffixIcon: Icon(Icons.arrow_drop_down), |
| 77 | + ), |
| 78 | + ); |
| 79 | + } |
| 80 | + )), |
| 81 | + Expanded(flex: 15, child: |
| 82 | + ColorPickerButton( |
| 83 | + initialColor: Colors.white, |
| 84 | + onColorChanged: widget.onColorChanged |
| 85 | + ) |
| 86 | + ), |
| 87 | + |
| 88 | + ]), |
| 89 | + //if (_showPlayers) |
| 90 | + // for(int i=0; i < md.teams.length; i++) |
| 91 | + // TeamRow( |
| 92 | + // defaultName: md.teams[i].name, |
| 93 | + // onNameChanged: (newName) { |
| 94 | + // List<Team> newTeams = List.from(md.teams); |
| 95 | + // newTeams[i] = md.teams[i].copyWith(name: newName); |
| 96 | + // mdl.value = md.copyWith(teams: newTeams); |
| 97 | + // }, |
| 98 | + // onColorChanged: (color) { |
| 99 | + // List<Team> newTeams = List.from(md.teams); |
| 100 | + // newTeams[i] = md.teams[i].copyWith(color: color.toHexString(includeHashSign: true)); |
| 101 | + // mdl.value = md.copyWith(teams: newTeams); |
| 102 | + // }, |
| 103 | + // initialShowPlayers: false |
| 104 | + // ), |
| 105 | + // TeamRow( |
| 106 | + // onNameChanged: (newName) { |
| 107 | + // if (newName.trim().isNotEmpty) { |
| 108 | + // List<Team> newTeams = List.from(md.teams); |
| 109 | + // newTeams.add(Team(newName, "", "#ffffff", [])); |
| 110 | + // mdl.value = md.copyWith(teams: newTeams); |
| 111 | + // } |
| 112 | + // }, |
| 113 | + // onColorChanged: (color) { |
| 114 | + // List<Team> newTeams = List.from(md.teams); |
| 115 | + // newTeams.add(Team("", "", color.toHexString(includeHashSign: true), [])); |
| 116 | + // mdl.value = md.copyWith(teams: newTeams); |
| 117 | + // }, |
| 118 | + // initialShowPlayers: false |
| 119 | + // ) |
| 120 | + ]); |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | + |
| 125 | +class CreatorWindow extends StatefulWidget { |
| 126 | + const CreatorWindow({super.key}); |
| 127 | + |
| 128 | + @override |
| 129 | + State<CreatorWindow> createState() => _CreatorWindowState(); |
| 130 | +} |
| 131 | + |
| 132 | +class _CreatorWindowState extends State<CreatorWindow> { |
| 133 | + late ValueNotifier<Matchday> mdl; |
| 134 | + |
| 135 | + @override |
| 136 | + void initState() { |
| 137 | + super.initState(); |
| 138 | + |
| 139 | + final Matchday md = Matchday(Meta(), [], [], [], []); |
| 140 | + mdl = ValueNotifier(md); |
| 141 | + } |
| 142 | + |
| 143 | + @override |
| 144 | + void dispose() { |
| 145 | + mdl.dispose(); |
| 146 | + |
| 147 | + super.dispose(); |
| 148 | + } |
| 149 | + |
| 150 | + //final textGroup = AutoSizeGroup(); |
| 151 | + |
| 152 | + Widget generalBlock(Matchday md) { |
| 153 | + return SizedBox.shrink(); |
| 154 | + } |
| 155 | + |
| 156 | + Widget teamsBlock(Matchday md) { |
| 157 | + return Column(children: [ |
| 158 | + for(int i=0; i < md.teams.length; i++) |
| 159 | + TeamRow( |
| 160 | + defaultName: md.teams[i].name, |
| 161 | + onNameChanged: (newName) { |
| 162 | + List<Team> newTeams = List.from(md.teams); |
| 163 | + newTeams[i] = md.teams[i].copyWith(name: newName); |
| 164 | + mdl.value = md.copyWith(teams: newTeams); |
| 165 | + }, |
| 166 | + onColorChanged: (color) { |
| 167 | + List<Team> newTeams = List.from(md.teams); |
| 168 | + newTeams[i] = md.teams[i].copyWith(color: color.toHexString(includeHashSign: true)); |
| 169 | + mdl.value = md.copyWith(teams: newTeams); |
| 170 | + }, |
| 171 | + initialShowPlayers: false |
| 172 | + ), |
| 173 | + TeamRow( |
| 174 | + onNameChanged: (newName) { |
| 175 | + if (newName.trim().isNotEmpty) { |
| 176 | + List<Team> newTeams = List.from(md.teams); |
| 177 | + newTeams.add(Team(newName, "", "#ffffff", [])); |
| 178 | + mdl.value = md.copyWith(teams: newTeams); |
| 179 | + } |
| 180 | + }, |
| 181 | + onColorChanged: (color) { |
| 182 | + List<Team> newTeams = List.from(md.teams); |
| 183 | + newTeams.add(Team("", "", color.toHexString(includeHashSign: true), [])); |
| 184 | + mdl.value = md.copyWith(teams: newTeams); |
| 185 | + }, |
| 186 | + initialShowPlayers: false |
| 187 | + ) |
| 188 | + ]); |
| 189 | + } |
| 190 | + |
| 191 | + Widget gamesBlock(Matchday md) { |
| 192 | + return SizedBox.shrink(); |
| 193 | + } |
| 194 | + |
| 195 | + @override |
| 196 | + Widget build(BuildContext context) { |
| 197 | + //final secondBgColor = Theme.of(context).scaffoldBackgroundColor; |
| 198 | + |
| 199 | + return PopScope(child: |
| 200 | + Scaffold(body: |
| 201 | + //body: SingleChildScrollView(child: |
| 202 | + ValueListenableBuilder<Matchday>( |
| 203 | + valueListenable: mdl, |
| 204 | + builder: (context, md, _) { |
| 205 | + return Column( |
| 206 | + //mainAxisSize: MainAxisSize.min, |
| 207 | + spacing: 20, |
| 208 | + children: [ |
| 209 | + //generalBlock(md), |
| 210 | + teamsBlock(md), |
| 211 | + //gamesBlock(md) |
| 212 | + ] |
| 213 | + ); |
| 214 | + } |
| 215 | + ) |
| 216 | + //) |
| 217 | + ) |
| 218 | + ); |
| 219 | + } |
| 220 | +} |
0 commit comments