flutter_country_state 0.2.5 flutter_country_state: ^0.2.5 copied to clipboard
A customizable Flutter package that displays all countries with it respective state.
import 'package:flutter/material.dart';
import 'package:flutter_country_state/flutter_country_state.dart';
import 'package:test_my_package/country_dialog.dart';
import 'package:test_my_package/state_bottom_sheet.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_country_states example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Country States example'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({ required this.title});
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String selectedCountry = "";
String selectedState = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: (){CountryBottomSheet().showCountry(context: context,
tap: (){
setState(() {
selectedCountry = Variables.country;
});
Navigator.pop(context);
}
);},
child: const Text('select country',
),
),
ElevatedButton(
onPressed: (){StateBottomSheet().showSelectedCountryStates(context: context,
tap:(){
setState(() {
selectedState = Variables.state;
});
Navigator.pop(context);
} );},
child: const Text('select state',
),
),
Text(Variables.country),
Text(Variables.state)
],
),
);
}
}
/*
GestureDetector(
child:Padding(
padding: const EdgeInsets.symmetric(horizontal:20),
child: Column(
children: <Widget>[
const Text( 'select state',
),
Text( Variables.state,
),
],
),
),
onTap: (){
showDialog(
context: context,
builder: (context) => SimpleDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0)),
elevation: 4,
children: <Widget>[
Align(
alignment: Alignment.topRight,
child: GestureDetector(
onTap: (){
//Redirect to the screen of your choice or pop out
},
child: const Padding(
padding: EdgeInsets.only(right:18.0),
child: Material(
color:Colors.red,
child: Text('Done',
),
),
)
),
),
SingleChildScrollView(child: StateDialog(
style: const TextStyle(),
subStringStyle: const TextStyle(),
substringBackground: Colors.blueAccent,
),)
],
)
);
}
),
*/