Last active
March 1, 2022 11:28
-
-
Save flutter-painter/fe2ffb284e6dd3b2d434308571f922c2 to your computer and use it in GitHub Desktop.
sandbox bag color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'sandbox', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'sandbox'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
List<Color> allColors = [Colors.pink, Colors.orange, Colors.blue]; | |
class _MyHomePageState extends State<MyHomePage> { | |
List<Widget> outputWidget = <Widget>[]; | |
Color face = allColors.first; | |
Color strap = allColors.first; | |
Color lining = allColors.first; | |
final cContainers = <Container>[]; | |
@override | |
initState(){ | |
super.initState(); | |
for (final c in allColors){ | |
cContainers.add(Container(color: c, child : Text(' _ '))); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('couleurs disponibles :'), | |
Row(mainAxisAlignment : MainAxisAlignment.center, children : cContainers), | |
Text('leather parts :'), | |
Row(mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('face:', style: TextStyle(color: face)), | |
DropdownButton<Color>( | |
value: face, | |
elevation: 16, | |
onChanged: (Color? newValue) { | |
setState(() { | |
face = newValue!; | |
}); | |
}, | |
items: allColors.map<DropdownMenuItem<Color>>((Color value) { | |
return DropdownMenuItem<Color>( | |
value: value, | |
child: Container(color: value), | |
); | |
}).toList(), | |
), | |
const SizedBox(width: 12), | |
Text('strap:', style: TextStyle(color: strap)), | |
DropdownButton<Color>( | |
value: strap, | |
elevation: 16, | |
onChanged: (Color? newValue) { | |
setState(() { | |
strap = newValue!; | |
}); | |
}, | |
items: allColors.map<DropdownMenuItem<Color>>((Color value) { | |
return DropdownMenuItem<Color>( | |
value: value, | |
child: Container(color: value), | |
); | |
}).toList(), | |
), | |
const SizedBox(width : 12), | |
Text('lining:', style: TextStyle(color: lining)), | |
DropdownButton<Color>( | |
value: lining, | |
elevation: 16, | |
onChanged: (Color? newValue) { | |
setState(() { | |
lining = newValue!; | |
}); | |
}, | |
items: allColors.map<DropdownMenuItem<Color>>((Color value) { | |
return DropdownMenuItem<Color>( | |
value: value, | |
child: Container(color: value), | |
); | |
}).toList(), | |
) | |
]), | |
if(outputWidget.isNotEmpty) Text('fils : '), | |
for(final o in outputWidget) o, | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
void _incrementCounter() async { | |
outputWidget = <Widget>[]; | |
final combosOutput = await getAvailableThreadColorsCombination(LeatherColorsInput(face,strap,lining)); | |
if(combosOutput == null){ | |
setState(() { | |
outputWidget = <Widget>[]; | |
print('output updated'); | |
}); | |
return ; | |
} | |
final listC1 = <Container>[]; | |
for (final c in combosOutput!.tone_on_tone.face_thread_colors){ | |
listC1.add(Container(color: c, child : Text('face'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC1)); | |
final listC2 = <Container>[]; | |
for (final c in combosOutput!.tone_on_tone.strap_thread_colors){ | |
listC2.add(Container(color: c, child: Text('strap'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC2)); | |
final listC3 = <Container>[]; | |
for (final c in combosOutput!.tone_on_tone.lining_thread_colors){ | |
listC3.add(Container(color: c, child: Text('lining'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC3)); | |
outputWidget.add(Text('///')); | |
// reversed | |
final listC4 = <Container>[]; | |
for (final c in combosOutput!.reversed.face_thread_colors){ | |
listC4.add(Container(color: c, child: Text('face'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC4)); | |
final listC5 = <Container>[]; | |
for (final c in combosOutput!.reversed.strap_thread_colors){ | |
listC5.add(Container(color: c, child: Text('strap'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC5)); | |
final listC6 = <Container>[]; | |
for (final c in combosOutput!.reversed.lining_thread_colors){ | |
listC6.add(Container(color: c, child: Text('lining'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC6)); | |
outputWidget.add(Text('///')); | |
// lining | |
final listC7 = <Container>[]; | |
for (final c in combosOutput!.free_form.face_thread_colors){ | |
listC7.add(Container(color: c, child: Text('face'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC7)); | |
final listC8 = <Container>[]; | |
for (final c in combosOutput!.free_form.strap_thread_colors){ | |
listC8.add(Container(color: c, child: Text('strap'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC8)); | |
final listC9 = <Container>[]; | |
for (final c in combosOutput!.free_form.lining_thread_colors){ | |
listC9.add(Container(color: c, child : Text('lining'))); | |
} | |
outputWidget.add(Row(mainAxisAlignment: MainAxisAlignment.center, children : listC9)); | |
setState(() { | |
outputWidget = outputWidget; | |
print('output updated'); | |
}); | |
} | |
} | |
class LeatherColorsInput{ | |
Color face_color; | |
Color strap_color; | |
Color lining_color; | |
LeatherColorsInput( | |
this.face_color, | |
this.strap_color, | |
this.lining_color, | |
); | |
} | |
class CombosOutput { | |
ThreadColorCombo tone_on_tone; | |
ThreadColorCombo reversed; | |
ThreadColorCombo free_form; | |
CombosOutput(this.tone_on_tone, this.reversed, this.free_form); | |
@override | |
toString(){ | |
return 'toneOnTone : $tone_on_tone\ninverted : $reversed\nother: $free_form'; | |
} | |
} | |
class ThreadColorCombo{ | |
List<Color> face_thread_colors; | |
List<Color> strap_thread_colors; | |
List<Color> lining_thread_colors; | |
int equality_mask; | |
ThreadColorCombo(this.face_thread_colors, this.strap_thread_colors, this.lining_thread_colors, this.equality_mask); | |
@override | |
toString(){ | |
return '${face_thread_colors.first.value}, $strap_thread_colors, $lining_thread_colors, $equality_mask'; | |
} | |
} | |
Future<CombosOutput?> getAvailableThreadColorsCombination(LeatherColorsInput lCI) async { | |
var leatherColorsCombo = ''; | |
if(lCI.face_color == lCI.strap_color && lCI.strap_color == lCI.lining_color){ | |
leatherColorsCombo = 'sameLeatherColors'; | |
} else if(lCI.face_color == lCI.strap_color && lCI.face_color != lCI.lining_color) { | |
leatherColorsCombo = 'diffLeatherColorsLiningColorIsUnique'; | |
} else if (lCI.face_color == lCI.lining_color && lCI.face_color != lCI.strap_color) { | |
leatherColorsCombo = 'diffLeatherColorsStrapColorIsUnique'; | |
} else{ //if (lCI.face_color != lCI.strap_color && lCI.face_color != lCI.lining_color){ | |
return null; | |
} | |
switch (leatherColorsCombo){ | |
case 'sameLeatherColors': | |
final d = [Colors.orange, Colors.blue, Colors.pink]..remove(lCI.face_color); | |
final _tone_on_tone = ThreadColorCombo( | |
d,d,d,111); | |
return CombosOutput(_tone_on_tone, _tone_on_tone, _tone_on_tone); | |
case 'diffLeatherColorsLiningColorIsUnique': | |
final _tone_on_toneV2 = ThreadColorCombo( | |
[lCI.face_color], | |
[lCI.strap_color], | |
[lCI.lining_color], | |
110); | |
final _reversedV2 = ThreadColorCombo( | |
[lCI.lining_color], | |
[lCI.lining_color], | |
[lCI.face_color], | |
110); | |
final dd = [Colors.orange, Colors.blue, Colors.pink]..remove(lCI.lining_color); | |
final _free_formV2 = ThreadColorCombo( | |
dd, | |
dd, | |
[lCI.lining_color], | |
110); | |
return CombosOutput(_tone_on_toneV2, _reversedV2, _free_formV2); | |
case 'diffLeatherColorsStrapColorIsUnique': | |
final _tone_on_toneV3 = ThreadColorCombo( | |
[lCI.face_color], | |
[lCI.strap_color], | |
[lCI.lining_color], | |
101); | |
final _reversedV3 = ThreadColorCombo( | |
[lCI.strap_color], | |
[lCI.face_color], | |
[lCI.face_color], | |
011); | |
final _free_formV3 = ThreadColorCombo( | |
allColors, // ? | |
allColors, // ? | |
[lCI.face_color], | |
110); | |
return CombosOutput(_tone_on_toneV3, _reversedV3, _free_formV3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment