class authorisePage extends StatefulWidget {
final String log;
final String pas;
authorisePage({super.key, required this.log, required this.pas});
@override
State<authorisePage> createState() => _authorisePage();
}
class _authorisePage extends State<authorisePage> {
TextEditingController login = TextEditingController(text: log);
TextEditingController password = TextEditingController(text: pas);
bool _hidePass = true;
bool _correctData = true;
Yallz
Asked:
2023-08-26 06:10:21 +0800 CST
import 'package:balance_it/bloc/home_page_cubit/home_page_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
bool calendarIsVisible = false;
bool pickerIsVisible = true;
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
final List<String> items = List.generate(20, (index) => 'Item $index');
DateTime dateNow = DateTime.now();
late String dateMonthText =
DateFormat('MMMM yyyy').format(dateNow).toUpperCase();
late AnimationController _controller;
late Animation<Rect> _clipRectAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_clipRectAnimation = Tween<Rect>(
begin: Rect.fromLTRB(0, 0, 100, 0), // Initial clip rect (top-left corner)
end: Rect.fromLTRB(
0, 0, 100, 100), // Final clip rect (covers the entire widget)
).animate(_controller);
}
void toggleVisibility() {
setState(() {
calendarIsVisible = !calendarIsVisible;
pickerIsVisible = !pickerIsVisible;
if (calendarIsVisible) {
_controller.forward();
} else {
_controller.reverse();
}
});
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => HomePageCubit(),
child: BlocConsumer<HomePageCubit, HomePageState>(
listener: (context, state) {
state.when(initial: () {}, loading: () {});
},
builder: (context, state) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: [
if (pickerIsVisible)
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
onPressed: () {
setState(() {
dateNow = DateTime(dateNow.year, dateNow.month - 1);
dateMonthText = DateFormat('MMMM yyyy')
.format(dateNow)
.toUpperCase();
});
},
child: const Icon(
Icons.keyboard_arrow_left,
color: Colors.white,
size: 40,
),
),
GestureDetector(
onTap: () {
setState(() {
toggleVisibility();
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Icon(Icons.calendar_month),
const Padding(padding: EdgeInsets.all(4)),
Text(
dateMonthText,
style: const TextStyle(fontSize: 18),
)
],
),
),
TextButton(
onPressed: () {
setState(() {
dateNow = DateTime(dateNow.year, dateNow.month + 1);
dateMonthText = DateFormat('MMMM yyyy')
.format(dateNow)
.toUpperCase();
});
},
child: const Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
size: 40,
),
),
],
),
AnimatedContainer(
duration: const Duration(milliseconds: 200),
height: calendarIsVisible ? 260.0 : 0.0,
child: calendarIsVisible
? AnimatedBuilder(
animation: _clipRectAnimation,
builder: (context, child) {
return ClipRect(
child: YearCalendarDialog(
dateNow: dateNow,
onMonthPicked: (DateTime month) {
setState(() {
dateNow = month;
dateMonthText = DateFormat('MMMM yyyy')
.format(month)
.toUpperCase();
toggleVisibility();
});
},
));
})
: const SizedBox.shrink(),
),
const Padding(
padding: EdgeInsets.only(top: 8.0),
child: SizedBox(
width: 360,
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Icon(Icons.payments),
Text(
'-12.000 RUB',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
fontSize: 16),
),
Text('Expences')
],
),
Column(
children: [
Icon(Icons.account_balance_wallet),
Text(
'118.000 RUB',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: 16),
),
Text('Balance')
],
),
Column(
children: [
Icon(Icons.account_balance),
Text(
'130.000 RUB',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16),
),
Text('Income')
],
),
],
)),
)
],
),
);
},
),
);
}
}
class YearCalendarDialog extends StatefulWidget {
final DateTime dateNow;
final Function(DateTime) onMonthPicked;
const YearCalendarDialog({
super.key,
required this.dateNow,
required this.onMonthPicked,
});
@override
State<YearCalendarDialog> createState() => _YearCalendarDialogState();
}
class _YearCalendarDialogState extends State<YearCalendarDialog> {
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Align(
alignment: Alignment.topRight,
child: TextButton(
onPressed: () {
widget.onMonthPicked(widget.dateNow);
},
child: const Icon(Icons.close)),
),
GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 50,
crossAxisCount: 3,
crossAxisSpacing: 1,
mainAxisSpacing: 1,
),
itemCount: 12,
itemBuilder: (BuildContext context, int index) {
final month = DateTime(widget.dateNow.year, index + 1);
final monthName = DateFormat('MMMM').format(month);
return GestureDetector(
onTap: () {
widget.onMonthPicked(month);
},
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
),
child: Center(
child: Text(
monthName,
style: const TextStyle(fontSize: 14),
),
),
),
);
},
),
],
);
}
}
Sergei Zhilinski
Asked:
2023-05-01 05:03:19 +0800 CST
我正在寻找各种工具和服务来促进我在 Flutter 中的工作。即,类似于图形编辑器的东西,我可以在其中将对象散布在屏幕周围,然后代码会返回给我(不是工作应用程序,而只是描述对象定位的代码)。从类别中——我把它放在中间,它又回到我身边
Center(child:Text('Бла-бла-бла')
我把对象放在屏幕的底部,但不是在中间,而是稍微靠边一点——就像
Align(alignment: FractionalOffset(dx,dy), child: text('бла-бла-бла'))
有类似的东西吗?我看到了类似的 HTML 构造函数,但我找不到任何用于 flutter 的东西。
Artorias
Asked:
2022-09-25 01:31:37 +0800 CST
import 'package:flutter/material.dart';
import 'package:flutter_application_1/pages/home.dart';
void main() => runApp(MaterialApp(
theme: ThemeData(primaryColor: Colors.amber),
home: Home(),
));
主页.dart
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
List todoList = [];
@override
void initState() {
super.initState();
todoList.addAll(['Buy milk', 'Wash dishes', 'купить картошку']);
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[600],
appBar: AppBar(
title: Text('Список делишек'),
backgroundColor: Colors.black54,
),
body: ListView.builder(
itemCount: todoList.length,
itemBuilder: (BuildContext context, int index) {
return Dismissible(
key: Key(todoList[index]),
child: Card(
child: ListTile(title: Text(todoList[index])),
));
}),
);
}
}
我做了这段代码,它抛出了一个错误:
“超级”调用的上下文无效。
在这部分代码中
@override
void initState() {
super.initState();
todoList.addAll(['Buy milk', 'Wash dishes', 'купить картошку']);
}
我不喜欢超级这个词 请告诉我如何解决它
Artorias
Asked:
2022-09-20 23:28:20 +0800 CST
void main() {
var bob = User('Bob', 20, true, ['footbal', 'Skate']);
// ..name = 'Bob'
// ..age = 40;
bob.info();
var alex = User('Alex', 25, false, ['Basketbol']);
}
class User{
String? name;
int? age;
bool? isHappy;
List<String>? hobbies;
User(name, age, [ishappy, hobbies]){
this.name = name;
this.age = age;
this.isHappy = isHappy;
this.hobbies = hobbies;
}
void info(){
var happy = isHappy ? 'happy' : 'not happy';
print('User $name is $age years old. He is $happy. His hobbies:');
for(var el in hobbies){
print(el);
}
}
}
错误:
Error compiling to JavaScript:
Info: Compiling with sound null safety
lib/main.dart:25:17:
Error: A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't.
var happy = isHappy ? 'happy' : 'not happy';
^
lib/main.dart:27:19:
Error: The type 'List<String>?' used in the 'for' loop must implement 'Iterable<dynamic>' because 'List<String>?' is nullable and 'Iterable<dynamic>' isn't.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
for(var el in hobbies){
^
Error: Compilation failed.
在这里制作代码: https ://dartpad.dartlang.org/ ?
我是编程新手,请告诉我,可能是什么问题。