Флаттер. Диалог показывает, что я хочу, но диапазон значений не движется - PullRequest
0 голосов
/ 25 апреля 2020

У меня есть рабочий код, но пользовательский интерфейс не хочет обновляться, и мои ползунки не двигаются (Запуск показывает, что значения действительно меняются)

вот мой код:

import 'package:flutter/material.dart';
import 'package:autobanas/database.dart';
import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';
import 'package:autobanas/users.dart';

class SearchPage extends StatefulWidget {
  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {

  double _starValue = 100;
  double _endValue = 5000;
  RangeValues values = RangeValues(100, 5000);

  @override
  Widget build(BuildContext context) {
    return StreamProvider<List<Users>>.value(
      value: DatabaseService().ads,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: const Text(
            'Skelbimu paieška',
            style: TextStyle(
              fontSize: 18,
              fontWeight: FontWeight.w700,
              color: Colors.blueGrey,
            ),
          ),
          actions: <Widget>[
            // action button
            IconButton(
                padding: EdgeInsets.only(right: 12),
                icon: Icon(
                  Icons.exit_to_app,
                  color: Colors.blueGrey,
                  size: 36.0,
                ),
                onPressed: () async {}),
            // action button
          ],
        ),
        backgroundColor: Colors.black12,
        body: Stack(
          children: <Widget>[
            Image(
              //height: MediaQuery.of(context).size.height / 2,
              fit: BoxFit.cover,
              image: AssetImage('assets/images/bg.jpg'),
            ),
            GestureDetector(
              onTap: () {

              },
            child: Column(
              children: <Widget>[
                SizedBox(
                  height: 25,
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
                  margin: EdgeInsets.fromLTRB(36, 12, 36, 12),
                  height: 50,
                  child: GestureDetector(
                    onTap: () { _showAlert(context, values);},
                    child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Expanded(
                        child: Text('Markė / modelis',
                            style: TextStyle(
                              color: Colors.blueGrey,
                              fontWeight: FontWeight.w700,
                            )),
                      ),
                      Expanded(
                        child: Text('Mercedes CLS 335 ',
                            textAlign: TextAlign.right,
                            style: TextStyle(
                              color: Colors.blueGrey,
                              fontWeight: FontWeight.w700,
                            )),
                      ),
                    ],
                  ),
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(width: 2, color: Colors.blueGrey),
                    borderRadius: BorderRadius.all(const Radius.circular(12)),
                  ),
                ),
              ],
              )
            ),
          ],
        ),
      ),
    );
  }

  void _showAlert(BuildContext context, values) {
    Dialog simpleDialog = Dialog(
      shape: RoundedRectangleBorder(
          borderRadius:
          BorderRadius.circular(20.0)), //this right here
      child: Container(
        width: MediaQuery.of(context).size.width - 64,
        height: 200,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Padding(
              padding: EdgeInsets.symmetric(vertical: 16),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Pasirinkite kainą',
                    style: TextStyle(
                      fontSize: 18,
                      color: Colors.blueGrey,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                ],
              ),
            ),
            Divider(thickness: 1, height: 0,),
            Padding(
              padding: EdgeInsets.fromLTRB(12, 22, 12, 12),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '€ ' + _starValue.toInt().toString() ,
                    style: TextStyle( color: Colors.redAccent, fontWeight: FontWeight.w900, fontSize: 18),
                  ),
                  Text(
                    _endValue.toInt().toString() + ' €',
                    style: TextStyle( color: Colors.redAccent, fontWeight: FontWeight.w900, fontSize: 18),
                  ),

                ],
              ),
            ),
            Container(
              child: RangeSlider(
                activeColor: Colors.redAccent,
                values: values,
                min: 0,
                max: 50000,
                divisions: 500,
                onChanged: (val){
                  setState(() {
                    if (val.end - val.start >= 100) {
                      values = val;
                    } else {
                      if (val.start == val.start) {
                        values = RangeValues(val.start, val.start + 100);
                      } else {
                        values = RangeValues(val.end - 100, val.end);
                      }
                    }
                    print(values);
                    _starValue = values.start.roundToDouble();
                    _endValue = values.end.roundToDouble();
                    print(_endValue);
                  });
                },
              ),
            ),
            Expanded(
              child: new Container(
                padding: new EdgeInsets.only(top: 12),
                decoration: new BoxDecoration(
                    color: Colors.redAccent,
                    borderRadius: new BorderRadius.only(
                        bottomLeft:  const  Radius.circular(20.0),
                        bottomRight: const  Radius.circular(20.0))

                ),
                child: new GestureDetector(
                  onTap:  () {} ,
                  child: Text(
                  'Patvirtinti',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 16.0,
                    fontWeight: FontWeight.w800,
                  ),
                  textAlign: TextAlign.center,
                ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
    showDialog(
        context: context, builder: (BuildContext context) => simpleDialog);
  }
}

Может кто-то дайте мне какие-нибудь советы / советы? я не знаком с флаттером и виджетами ..

Я видел несколько похожих вопросов, но ответы на него конкретно c на вопрос другого человека, я пытался реализовать его в своем коде, но безуспешно ..

...