Flutter 颤振值不变

Flutter 颤振值不变,flutter,Flutter,我正在尝试设置一组非常简单的单选按钮,这就是为什么它们无法工作的原因。我试着在一个类似的班级里设置这个,它成功了。我知道正在调用setstate,但出于某种原因,它没有更新单个单选按钮。这让我觉得这是一个与国家有关的奇怪问题 不管怎样,我们都会感激你的帮助。我的主要类是下面代码的第二部分 import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../bloc/

我正在尝试设置一组非常简单的单选按钮,这就是为什么它们无法工作的原因。我试着在一个类似的班级里设置这个,它成功了。我知道正在调用setstate,但出于某种原因,它没有更新单个单选按钮。这让我觉得这是一个与国家有关的奇怪问题

不管怎样,我们都会感激你的帮助。我的主要类是下面代码的第二部分

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../bloc/thembloc.dart';
import './components/textfield.dart';

class SignUp extends StatefulWidget {
  @override
  _SignUpState createState() => _SignUpState();
}

class _SignUpState extends State<SignUp> {

  /*
  ui for signup
  includes multiple textfields.
  includes all of the information that we'll need
  to collect for an user to register an account. 
  todo: wrap everything in a form, encrypt it and send it to a private server.
  */
  @override
  Widget build(BuildContext context) {
    double _height = MediaQuery.of(context).size.height;
    double _width = MediaQuery.of(context).size.width;
    final double _margin = 16.0;
    final double _promptWidth = _width - 32.0;
    final double _promptHeight = _height - 32.0;
    final double _textFieldWidth = _promptWidth - 32.0;
    int subscriberValue;

    void switchSubscriber(int value) {
      setState(() {
       subscriberValue = value; 
      });
    }

    return BlocBuilder(
        bloc: BlocProvider.of<ThemeBloc>(context),
        builder: (context, ThemeState state) {
          return Scaffold(
            resizeToAvoidBottomInset: false,
            resizeToAvoidBottomPadding: false,
            appBar: AppBar(
              centerTitle: true,
              title: Text(
                "smartmoney",
                style: BlocProvider.of<ThemeBloc>(context).currentState.themedata.primaryTextTheme.display2,
              ),

              // appbar
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                      bottomLeft: Radius.circular(8.0),
                      bottomRight: Radius.circular(8.0))),
              leading: IconButton(
                icon: Icon(
                  Icons.arrow_back,
                  color: BlocProvider.of<ThemeBloc>(context).currentState.themedata.buttonColor,
                ),
                onPressed: () {
                  print("going back");
                },
              ),
              backgroundColor: BlocProvider.of<ThemeBloc>(context).currentState.themedata.canvasColor,
            ),
            body: Container(
              height: _height,
              width: _width,
              color: BlocProvider.of<ThemeBloc>(context).currentState.themedata.backgroundColor,
              child: Column(
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(top: _margin),
                    child: Container(
                      decoration: BoxDecoration(
                         borderRadius: BorderRadius.all(Radius.circular(8.0)),
                         color: BlocProvider.of<ThemeBloc>(context).currentState.themedata.canvasColor,
                         boxShadow: [
                           BoxShadow(
                               spreadRadius: 0.0,
                               color: Colors.black38,
                               blurRadius: 6.0,
                               offset: Offset(0.0, 3.0)),
                         ]),
                      width: _promptWidth,
                      height: _promptHeight - 48 - _margin,
                      child: Column(
                        children: <Widget>[
                          Text("Let's get started",
                          style: BlocProvider.of<ThemeBloc>(context).currentState.themedata.primaryTextTheme.display2,
                          ),
                          Text("Enter your information to create an account",
                          style: BlocProvider.of<ThemeBloc>(context).currentState.themedata.primaryTextTheme.subtitle,
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 8.0),
                            child: StyledTextField(
                              textFieldWidth: _textFieldWidth,
                              helperText: "First name",
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 8.0),
                            child: StyledTextField(
                              textFieldWidth: _textFieldWidth,
                              helperText: "Last name",
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 8.0),
                            child: StyledTextField(
                              textFieldWidth: _textFieldWidth,
                              helperText: "Email",
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 8.0),
                            child: StyledTextField(
                              textFieldWidth: _textFieldWidth,
                              helperText: "Password",
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 8.0),
                            child: StyledTextField(
                              textFieldWidth: _textFieldWidth,
                              helperText: "Phone number",
                            ),
                          ),
                          Text("Subscriber type",
                          style: BlocProvider.of<ThemeBloc>(context).currentState.themedata.primaryTextTheme.display1,
                          ),
                          Radio(
                            groupValue: subscriberValue,
                            value: 0,
                            onChanged: (int value) => switchSubscriber(value),
                          ),
                          Radio(
                            groupValue: subscriberValue,
                            value: 1,
                            onChanged: (int value) => switchSubscriber(value),
                          )
                        ],
                      ),
                    ),
                  )
                ],
              ),
          ),
          );
        });
  }
}

import 'package:flutter/material.dart';
import './bloc/thembloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'ui/signin.dart';
import 'ui/signup.dart';
import 'ui/onboarding.dart';
import './ui/testing/whatthefuck.dart';

void main() {
  runApp(
    MaterialApp(
      home: SmartMoney(),
    )
    // SmartMoney()
  );
}

class SmartMoney extends StatefulWidget {
  @override
  _SmartMoneyState createState() => _SmartMoneyState();
}

class _SmartMoneyState extends State<SmartMoney> {

  final _themeBloc = ThemeBloc();

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        bloc: _themeBloc,
        child: SignUp(),
      );
  }
}
导入“包装:颤振/材料.省道”;
进口“包装:颤振团/颤振团.飞镖”;
导入“../bloc/thembloc.dart”;
导入“./components/textfield.dart”;
类注册扩展了StatefulWidget{
@凌驾
_SignUpState createState()=>\u SignUpState();
}
类_SignUpState扩展状态{
/*
注册用户界面
包括多个文本字段。
包括我们需要的所有信息
为用户注册帐户收取费用。
todo:将所有内容包装成一个表单,对其进行加密并将其发送到专用服务器。
*/
@凌驾
小部件构建(构建上下文){
double _height=MediaQuery.of(context).size.height;
double _width=MediaQuery.of(context).size.width;
最终双倍保证金=16.0;
最终双提示宽度=\u宽度-32.0;
最终双提示高度=\u高度-32.0;
最终双精度textFieldWidth=promptWidth-32.0;
int值;
无效交换用户(int值){
设置状态(){
subscriberValue=值;
});
}
返回BlocBuilder(
bloc:BlocProvider.of(上下文),
生成器:(上下文,地产状态){
返回脚手架(
resizeToAvoidBottomInset:false,
resizeToAvoidBottomPadding:false,
appBar:appBar(
标题:对,
标题:正文(
“智能货币”,
样式:BlocProvider.of(context).currentState.themedata.primaryTextTheme.display2,
),
//appbar
形状:圆形矩形边框(
borderRadius:仅限borderRadius(
左下角:半径。圆形(8.0),
右下角:半径。圆形(8.0)),
领先:IconButton(
图标:图标(
Icons.arrow_back,
颜色:BlocProvider.of(context).currentState.themedata.buttonColor,
),
已按下:(){
打印(“返回”);
},
),
backgroundColor:BlocProvider.of(context).currentState.themedata.canvasColor,
),
主体:容器(
高度:_高度,
宽度:_宽度,
颜色:BlocProvider.of(context).currentState.themedata.backgroundColor,
子:列(
儿童:[
填充物(
填充:仅限边缘设置(顶部:_边距),
子:容器(
装饰:盒子装饰(
borderRadius:borderRadius.all(半径.圆形(8.0)),
颜色:BlocProvider.of(context).currentState.themedata.canvasColor,
boxShadow:[
箱形阴影(
扩展半径:0.0,
颜色:颜色。黑色38,
半径:6.0,
偏移量:偏移量(0.0,3.0)),
]),
宽度:_promptWidth,
高度:_提示高度-48-_边距,
子:列(
儿童:[
文本(“让我们开始吧”,
样式:BlocProvider.of(context).currentState.themedata.primaryTextTheme.display2,
),
文本(“输入您的信息以创建帐户”,
样式:BlocProvider.of(context).currentState.themedata.primaryTextTheme.subtitle,
),
填充物(
填充:仅限边缘设置(顶部:8.0),
子:StyledTextField(
textFieldWidth:_textFieldWidth,
helperText:“名字”,
),
),
填充物(
填充:仅限边缘设置(顶部:8.0),
子:StyledTextField(
textFieldWidth:_textFieldWidth,
helperText:“姓氏”,
),
),
填充物(
填充:仅限边缘设置(顶部:8.0),
子:StyledTextField(
textFieldWidth:_textFieldWidth,
helperText:“电子邮件”,
),
),
填充物(
填充:仅限边缘设置(顶部:8.0),
子:StyledTextField(
textFieldWidth:_textFieldWidth,
helperText:“密码”,
),
),
填充物(
填充:仅限边缘设置(顶部:8.0),
子:StyledTextField(
textFieldWidth:_textFieldWidth,
helperText:“电话号码”,
),
),
文本(“订户类型”,
样式:BlocProvider.of(context).currentState.themedata.primaryTextTheme.display1,
),
无线电(
class _SignUpState extends State<SignUp> {

  // HAS TO BE CLASS MEMBER AND IT'S GOOD AN INITIAL VALUE TOO..
  int subscriberValue =1; // asuming that  1 is default radio button option 

  @override
  Widget build(BuildContext context) {
    //... some codes ...
    //int subscriberValue; REMOVE THIS LINE. YOU'RE LOSING THE VALUE IN EVERY setState call

    //You can define this method outside from build too.
    void switchSubscriber(int value) {
      setState(() {
        subscriberValue = value;
      });
    }
}