# Flutter Bloc State Not Changing/ Updating

T

#### Ta-Ty

##### Guest
Ta-Ty Asks: Flutter Bloc State Not Changing/ Updating
I am new to blocs in Flutter and I am trying to use them to create, read, edit, and store user inputted data. I am currently using a bloc for my app's onboarding process. Ideally, once the user creates an account using Firebase email & password authentication, they will be prompted to answer a list of questions. The problem is, my state does not changing from loading to loaded. I have it set up to display a circular progress bar until it is loaded, then the text will appear, but there is no state change. I could really use some guidance or insight please .

Main dart:

Code:
int? isViewed;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate();

final prefs = await SharedPreferences.getInstance();
Paint.enableDithering = true;

// This is for our onboarding screen
isViewed = prefs.getInt('onboard');

}

class MyApp extends StatelessWidget {

const MyApp({Key? key,

@override
Widget build(BuildContext context) {
return MultiRepositoryProvider(
providers: [
RepositoryProvider(
create: (context) => DatabaseRepository()
),
RepositoryProvider(
create: (context) => StorageRepository()
)
],
child: MultiBlocProvider(
providers: [
BlocProvider<OnboardingBloc>(
create: (context) => OnboardingBloc(
))
],
child: MaterialApp(
title: 'Strength',
debugShowCheckedModeBanner: false,
initialRoute: AccountOnboarding.routeName, // Splash Screen
routes: {
'/splash screen' : (context) => const SplashScreen(),
'/main onboarding' : (context) => const OnboardingScreen(),
'/landing' : (context) => LandingScreen(),
'/dashboard' : (context) => const Dashboard(),
'/profile onboarding' : (context) => const AccountOnboarding()
},

home: AccountOnboarding() // FINAL SCREEN IS SPLASH SCREEN
)),
);
}
}

Onboarding Bloc:

Code:
part 'onboarding_event.dart';
part 'onboarding_state.dart';

class OnboardingBloc extends Bloc<OnboardingEvent, OnboardingState> {
final DatabaseRepository _databaseRepository;
final StorageRepository _storageRepository;

OnboardingBloc({
required DatabaseRepository databaseRepository,
required StorageRepository storageRepository,
}) :
_databaseRepository = databaseRepository,
_storageRepository = storageRepository,
on<StartOnboarding>(_onStartOnboarding);
on<UpdateUser>(_onUpdateUser);
on<UpdateUserImage>(_onUpdateUserImage);
}

void _onStartOnboarding(
StartOnboarding event,
Emitter<OnboardingState> emit)
async {
await _databaseRepository.createUser(event.user);
}

void _onUpdateUser(
UpdateUser event,
Emitter<OnboardingState> emit) {
_databaseRepository.UpdateUser(event.user);
}
}

void _onUpdateUserImage(
UpdateUserImage event,
Emitter<OnboardingState> emit)
async{
User user = (state as OnboardingLoaded).user;

_databaseRepository.getUser(user.id!).listen((user) {
});
}
}
}

Onboarding States:

Code:
part of 'onboarding_bloc.dart';

abstract class OnboardingState extends Equatable {
const OnboardingState();

@override
List<Object> get props => [];
}

final User user;

@override
List<Object> get props => [user];
}

Onboarding Screen format:

Code:
class AccountOnboarding extends StatefulWidget {
const AccountOnboarding({Key? key}) : super(key: key);
static const String routeName = '/profile onboarding';

static Route route() {
return MaterialPageRoute(
settings: const RouteSettings(name: routeName),
builder: (context) => OnboardingScreen());
}

@override
State<AccountOnboarding> createState() => _AccountOnboardingState();

}

class _AccountOnboardingState extends State<AccountOnboarding> {

static const List<Tab> tabs = <Tab>[
Tab(text: 'Name'),
Tab(text: 'Age and Profile'),
Tab(text: 'Bio and Interests'),
Tab(text: 'Selection')
];

@override
Widget build(BuildContext context) {

return DefaultTabController(
length: tabs.length,
child: Builder(builder: (BuildContext context) {
final TabController tabController = DefaultTabController.of(context)!;
if (!tabController.indexIsChanging) {}
});
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color(0xff31708c),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
title: Row(
children: [
Expanded(
child: Image.asset('assets/images/Logo_Strength.png',
height: 50),
),
Expanded(
flex: 2,
child: RichText(
text: TextSpan(
fontSize: 30),
children: <TextSpan> [
TextSpan(text: 'Stren',
color: Colors.white,
fontWeight: FontWeight.bold,
letterSpacing: 1,
color: Colors.black.withOpacity(0.7),
offset: const Offset(1.5, 0.0))
])),

TextSpan(text: ';',
color: const Color(0xffef6a7a), fontWeight: FontWeight.bold,
letterSpacing: 1,
color: Colors.black.withOpacity(0.7),
offset: const Offset(1.5, 0.0))
])),

TextSpan(text: 'th',
color: Colors.white,
fontWeight: FontWeight.bold,
letterSpacing: 1,
color: Colors.black.withOpacity(0.7),
offset: const Offset(1.5, 0.0))
]))
],
),
),
),
],
)
),
body: TabBarView(
// physics: const NeverScrollableScrollPhysics(),
children: [
NamePage(tabController: tabController,),
ageAndPicture(tabController: tabController,),
bioAndInterests(tabController: tabController,),
SelectionPage(tabController: tabController,)
],
),
);
}

));
}}

First onboarding screen (where states are addressed):

Code:
class NamePage extends StatelessWidget {
final TabController tabController;

const NamePage({Key? key,
required this.tabController})
: super(key: key);

@override

Widget build(BuildContext context) {
double _height = MediaQuery.of(context).size.height;

return BlocBuilder<OnboardingBloc, OnboardingState>(
builder: (context, state) {
return Center(
child: CircularProgressIndicator(),
);
}

return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color(0xff31708c),

left: 30,
right: 30,
top: _height * 0.055,
bottom: _height * 0.05),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Column(
children: <Widget>[
Text('Here at Strength, we respect your preferences. How would you like to be addressed?',
color: Colors.white,
fontSize: 19,
fontWeight: FontWeight.w600
),
textAlign: TextAlign.center,),
top: _height * 0.22),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextField(
maxLength: 14,
maxLengthEnforcement: MaxLengthEnforcement.enforced,
onChanged: (value) {
user: state.user.copyWith(name: value)));
},
cursorColor: Colors.white,
color: Colors.white,
fontSize: 19,
height: 2
),
decoration: InputDecoration(
enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
filled: true,
color: Colors.white,
fontSize: 14.5,
fontWeight: FontWeight.w600
),
fontSize: 14.5,
fontWeight: FontWeight.w600
),
// counterText: "",
labelStyle:
color: Colors.white,
fontSize: 18),
hintText: 'Please call me . . .',
color: Colors.white54,
fontWeight: FontWeight.w600,
fontSize: 18),
border: InputBorder.none),
),
],
),
),),
],
),
],
),
Column(
children: [
Align(
alignment:
Alignment.topLeft,
child: Text('1/4',
color: Colors.white,
fontWeight: FontWeight.w500
),)),
const SizedBox(height: 5,),
const StepProgressIndicator(
totalSteps: 4,
currentStep: 1,
size: 3,
selectedColor: Colors.white,
unselectedColor: Color.fromARGB(255, 20, 83, 106),),
const SizedBox(height: 13,),
CustomButton(tabController: tabController)
],
),
],
),
),
);
}
else {
return const Text('Something went wrong.');
}
}
);
}
}

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### How does backpropagation through accuracy work?

• Константин Писаный
• Computer Science
• Replies: 0
Константин Писаный Asks: How does backpropagation through accuracy work?
I'm using a specific constraint on my predicted logits and adding it to the loss. In a nutshell, this constraint tries to minimize cross-overlap between the channels of my predictions. I'm using accuracy to calculate overlap and I'm curious how does the backpropagation works in this case.

I would appreciate any insights or helpful resources on this matter. Thank you.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### How to specify scale_pos_weight value at runtime in Hyperopt?

megjosh Asks: How to specify scale_pos_weight value at runtime in Hyperopt?
I want to use LighgbmClassifier for a binary Classification. for Hyper Parameter tuning I want to use Hyperopt. The Dataset is imbalanced. Using Sklearns class_weight.compute_class_weight as shown below

Code:
        clas_wts_arr = class_weight.compute_class_weight('balanced',np.unique(y_trn),y_trn)
self.scale_pos_wt = clas_wts_arr[0] / clas_wts_arr[1]

The following is the space parameter that I am passing to the objective function

Code:
        space = {'objective' : hp.choice('objective', objective_list),
'boosting' : hp.choice('boosting', boosting_list),
'metric' : hp.choice('metric', metric_list),
"max_depth": hp.quniform("max_depth", 1, 15,2),
'min_data_in_leaf': hp.quniform('min_data_in_leaf', 1, 256, 1),
'num_leaves': hp.quniform('num_leaves', 7, 150, 1),
'feature_fraction' : hp.quniform('feature_fraction', 0.5, 1, 0.01),
'min_gain_to_split' : hp.quniform('min_gain_to_split', 0.1, 5, 0.01),
'lambda_l1' : hp.uniform('lambda_l1', 0, 5),
'lambda_l2' : hp.uniform('lambda_l2', 0, 5),
'feature_pre_filter': False}

My question will the following set scale_pos_weight properly in the space dictionary

Code:
        #set scale pos weight explicitly
space['scale_pos_weight'] = self.scale_pos_wt

If that is wrong then what would be the correct way to set scale_pos_weight at runtime in the space dictionary that is passed to the Objective fn that is in turn passed to the fmin of Hyperopt.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### How to generate spatial scale-free nwtworks?

Criticalola Asks: How to generate spatial scale-free nwtworks?
I want to generate spatial scale-free networks for my project. Are there any python libraries that enable it?

I read about the BA model (https://www.science.org/doi/pdf/10.1126/science.286.5439.509) which seems like the pioneer of scale-free networks but I am not sure it takes the spatial aspect into the account.

Can anyone explain:

1. What is the difference between a spatial and non-spatial scale-free network?
2. Python libraries to generate a spatial scale-free network.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### Optimal Binary Search Trees Knuth

Varun Asks: Optimal Binary Search Trees Knuth
Knuth, Donald E. (1971), "Optimum binary search trees", Acta Informatica 1 (1): 14–25,doi:10.1007/BF00264289

Please have a look at this paper, specifically page 18 in which he tries to prove his lemma that $R_{0,n-1} \leq R_{0,n}$ here $R$ refers to the minimal optimal node which will be the root of the binary tree containing elements $a_{0} ... a_{n}$ .

I understood the idea of the proof using induction that for some $k \, j_{k}=i_{k}$ . Now the next part of the proof is cutting and replacing,I have understood perfectly till there. What i don't understand is how $F''$ weighted path length is equal to weighted path length of $F'$ for all $a_{n}$. Can anyone please give me a hint or a solution to that.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

#### [Solved] Summing values of different layers based on another

• user140119
• Geography
• Replies: 0
user140119 Asks: Summing values of different layers based on another
I have a layer (called here 'layer_top') made of multiple polygons (in orange in the picture). Each polygon of the 'layer_top' overlaps with polygons of other different layers (called here 1,2,3,...). Each of these layers, within the 'layer_top', has a column with a score value (like in the picture). I would like to get the sum of the scores of all polygons of the layers 1,2,3, ... contained in each polygon of the layer_top. I have searched for a solution in this forum and tried to join attributes by location (including summary), but the result is not what I want.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] About getInfo use in earthengine-api (Python)

• maohaitaocumtb maohaitaocumtb
• Geography
• Replies: 0
When I write the an algorithm in Google Earth Engine using JavaScript by using the Code Editor, it works fast. After thatif I use the Map.addLayer()， the result of algorithm can show in the map quickly.

However, after I translate the algorithm into the version of Python with the earthengine-api and I want to get some intermediate results, I need to use the .getInfo() function. According to the official tutorial, you shouldn't use getInfo() unless you absolutely need to. If you call getInfo() in your code, Earth Engine will open the container and tell you what's inside, but it will block the rest of your code until that's done. So this function will slow down my program.

How can I address this issue in Python?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

#### [Solved] Working with CIRCULARSTRING in OGR's sqlite dialect

• bugmenot123
• Geography
• Replies: 0
bugmenot123 Asks: Working with CIRCULARSTRING in OGR's sqlite dialect
ogrinfo ":memory:" -dialect sqlite -sql "SELECT ST_GeomFromText('Point(1 2)')" gives me a dataset with a geometry column:

Code:
INFO: Open of :memory:'
using driver SQLite' successful.

Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 1
Extent: (1.000000, 2.000000) - (1.000000, 2.000000)
Layer SRS WKT:
(unknown)
Geometry Column = ST_GeomFromText('Point(1 2)')
OGRFeature(SELECT):0
POINT (1 2)

but this does not work with some curve geometries, e. g. CIRCULARSTRING.

Code:
ogrinfo ":memory:" -dialect sqlite -sql "SELECT ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)')"

for example results in:

Code:
INFO: Open of :memory:'
using driver SQLite' successful.

Layer name: SELECT
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)'): String (0.0)
OGRFeature(SELECT):0
ST_GeomFromText('CIRCULARSTRING(1 5, 6 2, 7 3)') (String) = (null)

How can I work with such geometries when using the sqlite dialect? I would be fine with turning them into linear geometries in the query. Using -nlt CONVERT_TO_LINEAR is not a solution for me. The actual problem I am trying to solve is in third-party software that uses the same logic and there we can only edit the query (QGIS layer filters).

References:

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.