Aktualisieren des staatlichen Widgets aus dem Staatlosen Widget - FlatternAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Aktualisieren des staatlichen Widgets aus dem Staatlosen Widget - Flattern

Post by Anonymous »

Derzeit versuche ich, eine einfache Taschenrechner -App in Flutter zu erstellen. Es wird jedoch nicht wie erwartet aktualisiert. < /P>

import 'package:calculator/calcLogic.dart';
import 'package:flutter/material.dart';

class CalcHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Calculator'),
),
body: new CalcLayout());
}
}

class CalcLayout extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Column(children: getColumns());
}

List getColumns() {
var labels = [
"1", "2", "3", "+",
"4", "5", "6", "-",
"7", "8", "9", "*",
"C", "0", "=", "/",
""];

List list = new List();

list.add(new ResultString());
for (int i = 0; i < 4; i++) {
list.add(new Expanded(
child: new Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: new List.generate(4, (ind) {
var row = labels.sublist(i * 4, i * 4 + 4);
var text = row[ind];
return new Expanded(
child: new RaisedButton(
onPressed: () => _state.doUpdate(text),
child: new Text('$text')));
}))));
}

return list;
}
}

class ResultString extends StatefulWidget {
@override
createState() => new ResultState();
}

class ResultState extends State {
var _text = CalcLogic.getResult();

@override
Widget build(BuildContext context) {
return new Center(
child: new Text(
"$_text",
style: new TextStyle(fontSize: 40.0),
),
heightFactor: 2.0,
);
}

void doUpdate(String text) {
setState(() {
CalcLogic.doButton(text);
_text = CalcLogic.getResult();
});
}
}

ResultState _state = new ResultState();
< /code>

Weiß jemand, wie ich dieses Problem lösen kann, vorzugsweise ohne das gesamte Layout in einen Zustand zu konvertieren? < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post