Bu kodu yazınca sorunsuz şekilde Container içine istediğim değeri yazdırıyor. Ama bunu başka bir dart dosyasına import edip aynı containerı ona eklediğimde null diyor.
import 'package:cpu_reader/cpu_reader.dart';
import 'package:cpu_reader/cpuinfo.dart';
import 'package:flutter/material.dart';
String freqq;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('CPU Reader'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(children: [
Container(
child: Text(freqq),
),
FutureBuilder<CpuInfo>(
future: CpuReader.cpuInfo,
// ignore: missing_return
builder: (context, AsyncSnapshot<CpuInfo> snapshot) {
CpuInfo info = snapshot.data;
if (snapshot.hasData) {
freqq = info.abi;
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: []));
}
}),
StreamBuilder<CpuInfo>(
stream: CpuReader.cpuStream(500),
builder: (_, AsyncSnapshot<CpuInfo> snapshot) {
if (snapshot.hasData) {
return Column(
children: buildFreqList(snapshot),
);
}
return Text('No data!');
}),
]))));
}
List<Row> buildFreqList(AsyncSnapshot<CpuInfo> snapshot) {
return snapshot.data.currentFrequencies.entries
.map((entry) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text('CPU ${entry.key} '), Text('${entry.value}')]))
.toList();
}
}