Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions assets/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions lib/components/bottom_navigation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class BottomNavigation extends StatefulWidget {
const BottomNavigation({Key? key, required this.onSelect}) : super(key: key);

final Function(int) onSelect;

@override
State<BottomNavigation> createState() => _BottomNavigationState();
}

class _BottomNavigationState extends State<BottomNavigation> {
int selected = 1;

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
setState(() {
selected = 1;
widget.onSelect(1);
});
},
icon: SvgPicture.asset(
'assets/globe.svg',
color: selected == 1 ? Colors.pink : const Color(0xFF292929),
),
),
IconButton(
iconSize: 65,
padding: const EdgeInsets.only(bottom: 20),
onPressed: () {
setState(() {
selected = 2;
widget.onSelect(2);
});
},
icon: SvgPicture.asset(
'assets/plus.svg',
),
),
IconButton(
onPressed: () {
setState(() {
selected = 3;
widget.onSelect(3);
});
},
icon: SvgPicture.asset(
'assets/profile.svg',
color: selected == 3 ? Colors.pink : const Color(0xFF292929),
),
),
],
);
}
}
86 changes: 60 additions & 26 deletions lib/components/room_card.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,90 @@
import 'package:flutter/material.dart';

enum RoomStatus { waitingForPlayers, awaitingForAccept, started }
String calculateMembersCountLabel(int count) {
if (count % 10 == 1 && count % 100 != 11) {
return "человек";
} else if (count % 10 >= 2 &&
count % 10 <= 4 &&
(count % 100 < 10 || count % 100 >= 20)) {
return "человека";
} else {
return "человек";
}
}

enum RoomStatus {
waitingForPlayers(name: "Ожидаем игроков", color: Colors.yellow),
awaitingForAccept(name: "Ожидаем подтверждения", color: Colors.red),
started(name: "Игра началась", color: Colors.green);

const RoomStatus({
required this.name,
required this.color,
});

final String name;
final Color color;
}

class RoomCard extends StatelessWidget {
const RoomCard(
{super.key,
required this.name,
required this.membersCount,
required this.status});
const RoomCard({
super.key,
required this.name,
required this.membersCount,
required this.status,
});

final String name;
final int membersCount;
final RoomStatus status;

@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade400),
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
// ignore: prefer_const_literals_to_create_immutables
boxShadow: [
const BoxShadow(
color: Colors.grey,
spreadRadius: 3,
blurRadius: 7,
offset: Offset(0, 7))
],
color: Colors.white),
padding: const EdgeInsets.symmetric(vertical: 24, horizontal: 28),
return Card(
elevation: 5,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10))),
child: Container(
padding: const EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name),
Text(
name,
style: const TextStyle(
fontSize: 20,
),
),
const SizedBox(height: 10),
Text("$membersCount человек"),
Text(
"$membersCount ${calculateMembersCountLabel(membersCount)}",
style: TextStyle(
fontSize: 16,
color: Colors.black.withOpacity(0.5),
),
),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(status.name),
const SizedBox(height: 10),
const Text("скоро начало")
Text(
status.name,
style: TextStyle(
color: status.color,
fontSize: 16,
),
),
],
)
],
));
),
),
);
}
}
134 changes: 54 additions & 80 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:secret_santa_flutter/components/bottom_navigation.dart';
import 'package:secret_santa_flutter/components/room_card.dart';

void main() {
Expand All @@ -8,113 +11,84 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Тайный дед мороз',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(title: 'Тайный дед мороз'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
var selected = 0;

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const RoomCard(
name: "aboa",
membersCount: 2,
status: RoomStatus.awaitingForAccept),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
return Material(
child: SafeArea(
child: Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 70,
child: Container(
alignment: Alignment.center,
child: const Text(
"Список комнат",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0),
child: ListView.builder(
itemCount: 2,
itemBuilder: (context, idx) {
return Container(
padding: const EdgeInsets.only(bottom: 10.0),
child: const RoomCard(
name: "aboba",
membersCount: 3,
status: RoomStatus.awaitingForAccept),
);
},
),
),
),
SizedBox(
height: 100,
child: BottomNavigation(
onSelect: (int selected) {
setState(() => this.selected = selected);
log("Selected: $selected");
},
),
)
],
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Loading