Advertisement
Guest User

Main

a guest
Jan 23rd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. import 'dart:math';
  2. import 'dart:ui';
  3. import 'package:flutter/material.dart';
  4.  
  5. List<Widget> _list = new List<Widget>();
  6. final projectName = TextEditingController();
  7. final double sizeOfTile = window.physicalSize.width / 3 - 90;
  8. final List<Color> colors = [Color(0xFF7DE9FF), Color(0xFFA07DFF),
  9. Color(0xFFFD7DFF), Color(0xFFFA5F67),
  10. Color(0xFFE6925E), Color(0xFFF5DE5D),
  11. Color(0xFF6EF54C), Color(0xFF43FA9C)];
  12. void main() {
  13. runApp(
  14. new MaterialApp(
  15. debugShowCheckedModeBanner: false,
  16. initialRoute: '/',
  17. routes: {
  18. '/': (BuildContext context) => MainMenu(),
  19. '/counter': (BuildContext context) => Counter()
  20. },
  21. )
  22. );
  23. }
  24.  
  25. class MainMenu extends StatefulWidget{
  26. _MainMenu createState() => _MainMenu();
  27. }
  28.  
  29. class _MainMenu extends State<MainMenu> {
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33.  
  34. backgroundColor: Color(0xFFE8F8FF),
  35. appBar: new AppBar(
  36. title: new Text("Мои проекты"),
  37. ),
  38. body: GridView.count(
  39. crossAxisCount: 2,
  40. children: _list.toList()
  41. ),
  42. bottomNavigationBar: new BottomNavigationBar(items: [
  43. new BottomNavigationBarItem(
  44. icon: new Icon(Icons.home),
  45. title: new Text("Главная")
  46. ),
  47. new BottomNavigationBarItem(
  48. icon: new Icon(Icons.stars),
  49. title: new Text("Схемы")
  50. ),
  51. new BottomNavigationBarItem(
  52. icon: new Icon(Icons.help_outline),
  53. title: new Text("Советы")
  54. )
  55. ]),
  56. floatingActionButton: new FloatingActionButton(
  57. onPressed: addProject,
  58. backgroundColor: Colors.blueAccent,
  59. child: new Icon(Icons.add),
  60. ),
  61. );
  62. }
  63. //добавляет проект в меню
  64. void addProject() {
  65. showDialog(
  66. context: context,
  67. builder: (context){
  68. return AlertDialog(
  69. title: Text("Новый проект"),
  70. content: TextField(
  71. controller: projectName,
  72. ),
  73. actions: <Widget>[
  74. new FlatButton(
  75. child: Text("ОТМЕНА"),
  76. onPressed: (){
  77. projectName.text = "";
  78. Navigator.of(context).pop();
  79. }
  80. ),
  81. new FlatButton(
  82. child: Text("ОК"),
  83. onPressed: (){
  84. if(projectName.text.compareTo("") != 0)
  85. addElementToMenu(); //непосредственно создание кнопки и добавление в _list
  86. projectName.text = "";
  87. Navigator.of(context).pop();
  88. },
  89. )
  90. ],
  91. );
  92. }
  93. );
  94. }
  95. //непосредственно создание кнопки и добавление в _list
  96. void addElementToMenu(){
  97. setState(() {
  98. final GlobalKey key_text = new GlobalKey();
  99. _list.add(
  100. Center(
  101. child: Container(
  102. width: sizeOfTile,
  103. height: sizeOfTile,
  104. child: ButtonTheme(
  105. height: sizeOfTile,
  106. buttonColor: colors[new Random.secure().nextInt(8)],
  107. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
  108. child: RaisedButton(
  109. key: new GlobalKey(),
  110. onPressed: () {
  111. Navigator.pushNamed(context, '/counter');
  112.  
  113. },
  114. child: new Text(
  115. projectName.text.toUpperCase(),
  116. style: new TextStyle(
  117. fontFamily: 'projectName1',
  118. fontSize: getFont(projectName.text),
  119. fontWeight: FontWeight.bold,
  120. height: 1.2
  121. ),
  122. textAlign: TextAlign.center,
  123. key: key_text,
  124. ),
  125. ),
  126.  
  127. ),
  128. )
  129. )
  130. );
  131. });
  132. }
  133.  
  134. double getFont(String text){
  135. double fontSize = 34;
  136. int max = 0;
  137. List arr = text.split(" ");
  138. for (String a in arr)
  139. if( a.length > max)
  140. max = a.length;
  141. if (max > 7)
  142. fontSize = 37 - max * 1.4;
  143. return fontSize;
  144. }
  145. }
  146.  
  147. class Counter extends StatefulWidget{
  148. _Counter createState() => _Counter();
  149. }
  150.  
  151. //новое окно в котором я хочу присвоить имя заголовку из текста кнопки
  152. class _Counter extends State{
  153. @override
  154. Widget build(BuildContext context) {
  155. return Scaffold(
  156. backgroundColor: Color(0xFFE8F8FF),
  157. appBar: new AppBar(
  158. title: new Text(projectName.text),
  159. ),
  160. body: Center(),
  161. );
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement