Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:math';
- import 'dart:ui';
- import 'package:flutter/material.dart';
- List<Widget> _list = new List<Widget>();
- final projectName = TextEditingController();
- final double sizeOfTile = window.physicalSize.width / 3 - 90;
- final List<Color> colors = [Color(0xFF7DE9FF), Color(0xFFA07DFF),
- Color(0xFFFD7DFF), Color(0xFFFA5F67),
- Color(0xFFE6925E), Color(0xFFF5DE5D),
- Color(0xFF6EF54C), Color(0xFF43FA9C)];
- void main() {
- runApp(
- new MaterialApp(
- debugShowCheckedModeBanner: false,
- initialRoute: '/',
- routes: {
- '/': (BuildContext context) => MainMenu(),
- '/counter': (BuildContext context) => Counter()
- },
- )
- );
- }
- class MainMenu extends StatefulWidget{
- _MainMenu createState() => _MainMenu();
- }
- class _MainMenu extends State<MainMenu> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Color(0xFFE8F8FF),
- appBar: new AppBar(
- title: new Text("Мои проекты"),
- ),
- body: GridView.count(
- crossAxisCount: 2,
- children: _list.toList()
- ),
- bottomNavigationBar: new BottomNavigationBar(items: [
- new BottomNavigationBarItem(
- icon: new Icon(Icons.home),
- title: new Text("Главная")
- ),
- new BottomNavigationBarItem(
- icon: new Icon(Icons.stars),
- title: new Text("Схемы")
- ),
- new BottomNavigationBarItem(
- icon: new Icon(Icons.help_outline),
- title: new Text("Советы")
- )
- ]),
- floatingActionButton: new FloatingActionButton(
- onPressed: addProject,
- backgroundColor: Colors.blueAccent,
- child: new Icon(Icons.add),
- ),
- );
- }
- //добавляет проект в меню
- void addProject() {
- showDialog(
- context: context,
- builder: (context){
- return AlertDialog(
- title: Text("Новый проект"),
- content: TextField(
- controller: projectName,
- ),
- actions: <Widget>[
- new FlatButton(
- child: Text("ОТМЕНА"),
- onPressed: (){
- projectName.text = "";
- Navigator.of(context).pop();
- }
- ),
- new FlatButton(
- child: Text("ОК"),
- onPressed: (){
- if(projectName.text.compareTo("") != 0)
- addElementToMenu(); //непосредственно создание кнопки и добавление в _list
- projectName.text = "";
- Navigator.of(context).pop();
- },
- )
- ],
- );
- }
- );
- }
- //непосредственно создание кнопки и добавление в _list
- void addElementToMenu(){
- setState(() {
- final GlobalKey key_text = new GlobalKey();
- _list.add(
- Center(
- child: Container(
- width: sizeOfTile,
- height: sizeOfTile,
- child: ButtonTheme(
- height: sizeOfTile,
- buttonColor: colors[new Random.secure().nextInt(8)],
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
- child: RaisedButton(
- key: new GlobalKey(),
- onPressed: () {
- Navigator.pushNamed(context, '/counter');
- },
- child: new Text(
- projectName.text.toUpperCase(),
- style: new TextStyle(
- fontFamily: 'projectName1',
- fontSize: getFont(projectName.text),
- fontWeight: FontWeight.bold,
- height: 1.2
- ),
- textAlign: TextAlign.center,
- key: key_text,
- ),
- ),
- ),
- )
- )
- );
- });
- }
- double getFont(String text){
- double fontSize = 34;
- int max = 0;
- List arr = text.split(" ");
- for (String a in arr)
- if( a.length > max)
- max = a.length;
- if (max > 7)
- fontSize = 37 - max * 1.4;
- return fontSize;
- }
- }
- class Counter extends StatefulWidget{
- _Counter createState() => _Counter();
- }
- //новое окно в котором я хочу присвоить имя заголовку из текста кнопки
- class _Counter extends State{
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Color(0xFFE8F8FF),
- appBar: new AppBar(
- title: new Text(projectName.text),
- ),
- body: Center(),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement